c# - GetWindowLong(int hWnd, GWL_STYLE) 在 c# 中返回奇怪的数字

标签 c#

我使用 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/

相关文章:

c# - 如何将项目添加到动态创建的select(html)控件

c# - 从回调调用时,ASP.NET Core SignalR 客户端对象处理异常

c# - 如何在 LINQ 中动态添加或删除 where 子句

c# - 如何在c#中实现一个循序渐进的按钮?

c# - 无法加载文件或程序集 'VSLangProj80'

.NET 的 Javascript 解释器

c# - 当模型中的属性更改时得到通知

c# - exe 中发生类型为 'System.IO.FileLoadException' 的未处理异常

c# - 查找两个字符串之间的不同单词

c# - 在 C# 中使用字符串调用方法时出现 "Object does not match target type"