我在理解一件特定的事情时遇到了一些困难。 我的电脑运行的是 64 位 Windows,所以
std::cout << sizeof(HANDLE) << std::endl;
std::cout << sizeof(HWND) << std::endl;
std::cout << sizeof(int*) << std::endl;
全部打印 8,即 8 个字节(64 位)。
现在,在窗口过程中
LRESULT __stdcall wndProc(HWND, UINT, WPARAM, LPARAM lParam)
WPARAM 和 LPARAM 的大小(以字节为单位)也是 8。 然而,我记得在 Petzold 的书中读到过,有些消息的窗口句柄存储在 LPARAM 参数的 LOWORD 或 HIWORD 中。 例如,
HWND childHandle = (HWND)LOWORD(lParam);
这怎么可能? lParam的HIWORD,是一个32位整数的前两个字节?为了在 LPARAM 中存储句柄,是否需要全部八个字节?
谢谢!
最佳答案
快速搜索会找到 this MSDN page指出此方法用于 16 位应用程序,并在迁移到 32 位架构后发生了变化:
You extract the remaining two values in this way in the 16-bit framework:
HWND hWndCtrl = (HWND)LOWORD(lParam); //Control handle
int nCode = HIWORD(lParam); //Notification code
You extract them this way in the 32-bit framework:
HWND hWndCtrl = (HWND)lParam; //Control handle
int nCode = HIWORD(wParam); //Notification code
关于c++ - Win32 API - 将 LO/HIWORD 转换为 HANDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153123/