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);
- }
- }
- }
- }

Akash VarshneyRank #1,895 · 780 reputationPosted Sep 6, 2016, 2:29 AM EDT
Jim Tat52 reputationPosted Sep 6, 2016, 2:32 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Sep 6, 2016, 2:36 AM EDT
Jim Tat52 reputationPosted Sep 6, 2016, 2:46 AM EDT
Jim Tat52 reputationPosted Sep 6, 2016, 6:44 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 6, 2016, 6:21 AM EDT