Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
6
Reply
How To Check If A Window Is Minimized In C#
Jim Tat
Sep 6 2016 6:06 AM
463
Reply
Hello, I need to check if a window is minimized in c# Here is what I did:
{
class
RestoreWindow
{
[DllImportAttribute(
"user32.dll"
)]
public
static
extern
IntPtr FindWindow(
string
lpClassName,
string
lpWindowName);
[DllImportAttribute(
"user32.dll"
)]
public
static
extern
bool
ShowWindow(IntPtr hWnd,
int
nCmdShow);
[DllImportAttribute(
"user32.dll"
)]
public
static
extern
bool
SetForegroundWindow(IntPtr hWnd);
[DllImport(
"user32.dll"
)]
[
return
: MarshalAs(UnmanagedType.Bool)]
static
extern
bool
IsIconic(IntPtr hWnd);
public
static
void
MaximizeWindowIfMinized(
string
windowName,Form f1)
{
try
{
var instance = FindWindow(
null
, windowName);
if
(IsIconic(instance))
{
Button btn =
new
Button();
btn.Width = 10;
btn.Height = 10;
f1.Controls.Add(btn);
MessageBox.Show(
"Window is minimized"
);
// ShowWindow(instance, 1);
//SetForegroundWindow(instance);
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
But when I compile nothing happen , do you have any idea ?
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
barcode how to program ?
how to split and merge file