首页 文章

使用EnumChildWindows确定IntPtr实例的位数

提问于
浏览
2

我发布了一个类似的问题here但决定重新发布重点关注部分问题 .

我在32位WinForms应用程序的64位Windows 7上使用EnumWindows和EnumChildWindows枚举Windows . 这是宣言:

public delegate int EnumWindowsCallback (System.IntPtr hWnd, System.IntPtr lParam);

[DllImport("user32.Dll")]
public static extern bool EnumWindows (EnumWindowsCallback lpEnumCallbackFunc, IntPtr lParam);

[DllImport("user32")]
public static extern bool EnumChildWindows (IntPtr hWnd, EnumWindowsCallback lpEnumCallbackFunc, IntPtr lParam);

我将 [Process.GetProcesses()[i].MainWindowHandle] 作为参数发送到 [EnumWindows] 以枚举所有进程的所有子窗口 .

调用 [EnumChildWindows] 时, [hWnd] 参数可以是在32位或64位进程中运行的窗口的句柄 . 由于我的应用程序是32位,如何判断是否调用 [hWnd.ToInt32()][hWnd.ToInt64()] . 我需要调用两个函数中的一个来比较一个IntPtr到另一个 .

上下文:Windows 7(64位),VS 2010,WinForms(32位) .

1 回答

  • 2

    你不应该做任何特殊的事情, hwnd 不是一个指针它是一个HANDLE而对于这种类型的64位Windows guarantees只有低32位是重要的,所以它们可以自由共享 .

相关问题