gpt4 book ai didi

c# - 如何检查另一个应用程序是否最小化?

转载 作者:太空狗 更新时间:2023-10-29 19:52:16 29 4
gpt4 key购买 nike

如何检查另一个应用程序是否被最小化?例如在这样的循环中:

foreach(Process p in processes)
{
// Does a process have a window?
// If so, is it minimized, normal, or maximized
}

最佳答案

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

private struct WINDOWPLACEMENT {
public int length;
public int flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}

if (p.MainWindowHandle != IntPtr.Zero) {
if (p.MainWindowTitle.Contains("Notepad")) {
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
GetWindowPlacement(p.MainWindowHandle, ref placement);
switch (placement.showCmd) {
case 1:
Console.WriteLine("Normal");
break;
case 2:
Console.WriteLine("Minimized");
break;
case 3:
Console.WriteLine("Maximized");
break;
}
}
}

关于c# - 如何检查另一个应用程序是否最小化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1003073/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com