我使用 GetWindowLong 窗口 api 在 C# 中获取窗口的当前窗口状态。
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
Process[] processList = Process.GetProcesses();
foreach (Process theprocess in processList)
{
long windowState = GetWindowLong(theprocess.MainWindowHandle, GWL_STYLE);
MessageBox.Show(windowState.ToString());
}
我希望在 http://www.autohotkey.com/docs/misc/Styles.htm 上获得数字,但我得到的数字是 -482344960、-1803550644 和 382554704。
我需要转换 windowState 变量吗??如果是这样,为了什么?
最佳答案
这些值有什么奇怪的?例如,482344960
等同于 0x1CC00000
,它看起来像是您可能希望看到的窗口样式。查看您链接到的样式引用,即 WS_VISIBLE | WS_CAPTION | 标题0xC000000
。
例如,如果您想测试 WS_VISIBLE
,您可以执行如下操作:
int result = GetWindowLong(theprocess.MainWindowHandle, GWL_STYLE);
bool isVisible = ((result & WS_VISIBLE) != 0);
关于c# - GetWindowLong(int hWnd, GWL_STYLE) 在 c# 中返回奇怪的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1271220/