我遇到一种情况,我需要捕获另一个窗口的窗口状态更改(该窗口不属于我的应用程序,并且不是我编写的。我认为它是用 C++ 编写的)。
实际上我正在使用一个单独的线程,我不断地执行 GetWindowState 并在该值更改时触发自定义事件(我有窗口的句柄),但我想知道是否有更好的方法
Thanks,
附:
我正在使用 winform 如果有任何用处
//use this in a timer or hook the window
//this would be the easier way
using System;
using System.Runtime.InteropServices;
public static class WindowState
{
[DllImport("user32")]
private static extern int IsWindowEnabled(int hWnd);
[DllImport("user32")]
private static extern int IsWindowVisible(int hWnd);
[DllImport("user32")]
private static extern int IsZoomed(int hWnd);
[DllImport("user32")]
private static extern int IsIconic(int hWnd);
public static bool IsMaximized(int hWnd)
{
if (IsZoomed(hWnd) == 0)
return false;
else
return true;
}
public static bool IsMinimized(int hWnd)
{
if (IsIconic(hWnd) == 0)
return false;
else
return true;
}
public static bool IsEnabled(int hWnd)
{
if (IsWindowEnabled(hWnd) == 0)
return false;
else
return true;
}
public static bool IsVisible(int hWnd)
{
if (IsWindowVisible(hWnd) == 0)
return false;
else
return true;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)