[英]How to detect is a window of another process minimized or maximized?
Currently I'm making a small gadget that made in WPF. 目前,我正在制作一个使用WPF制作的小工具。 It shows and hides according to another window's state. 它根据另一个窗口的状态显示和隐藏。
So, let me name that another window be A. When A get shown or maximized, my gadget shows. 因此,我将另一个窗口命名为A。当显示A或最大化A时,我的小工具就会显示。 When A minimized, my gadget hides. 当A最小化时,我的小工具会隐藏。
So, how can I detect the change in state of a window of another process which is not in .NET? 那么,如何检测不在.NET中的另一个进程的窗口状态变化? Btw sorry for my bad English :P 顺便说一句我的英语不好:P
It's only part of the solution. 这只是解决方案的一部分。 If you know the title of the other window: 如果您知道另一个窗口的标题:
Process process = Process.GetProcesses().Where(p => p.MainWindowTitle == "Title of window").SingleOrDefault();
if (process != null) {
IntPtr wHnd = process.MainWindowHandle;
Console.WriteLine("Minimized: " + IsIconic(wHnd));
}
and: 和:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsIconic(IntPtr hWnd);
You'll want to get the HWND from the process you want to reach. 您将要从想要达到的过程中获取HWND。
How to get main window handle from process id? 如何从进程ID获取主窗口句柄?
It requires loading win32 libraries in your C# WPF app like below. 它需要在C#WPF应用程序中加载win32库,如下所示。
How can I use EnumWindows to find windows with a specific caption/title? 如何使用EnumWindows查找带有特定标题/标题的窗口?
Once you have the HWND, you can check the visibility of the app by a combination of the WS_VISIBLE and WS_MAXIMIZE properties. 拥有HWND之后,您可以结合使用WS_VISIBLE和WS_MAXIMIZE属性来检查应用程序的可见性。
How can I check if a window has WS_VISIBLE to set? 如何检查窗口是否设置了WS_VISIBLE? (or if is visible) (或可见)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.