Hello, I need to check if a window is minimized in c# Here is what I did:
But when I compile nothing happen , do you have any idea ?
C#:
{
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);
}
}
}
}