congdantoancau

Detect window is minimed

Nov 12th, 2021
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. //https://stackoverflow.com/questions/29327301/how-to-detect-is-a-window-of-another-process-minimized-or-maximized/29327657
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14.  
  15. namespace DetectMinimizedWindow
  16. {
  17.     public partial class Form1 : Form
  18.     {
  19.         [DllImport("user32.dll")]
  20.         [return: MarshalAs(UnmanagedType.Bool)]
  21.         static extern bool IsIconic(IntPtr hWnd);
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void button1_Click(object sender, EventArgs e)
  28.         {
  29.             Process process = Process.GetProcesses()
  30.                 .Where(p => p.MainWindowTitle == "Untitled - Notepad").SingleOrDefault();
  31.             if (process != null)
  32.             {
  33.                 IntPtr wHnd = process.MainWindowHandle;
  34.                 Console.WriteLine("Minimized: " + IsIconic(wHnd));
  35.                 MessageBox.Show("Minimized: " + IsIconic(wHnd));
  36.             }
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment