消息处理程序未调用窗口过程
我正在编写 Windows Api 包装器,但遇到了问题。我正在抽象窗口过程 (WndProc) 并编写一个静态 MsgHandler,它将调用我的 WinHandler 类的 WndProc。代码如下:
LRESULT CALLBACK WinHandle::MsgHandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
WinHandle* wnd = 0;
if (msg == WM_NCCREATE)
{
::SetWindowLong(hwnd,GWL_USERDATA,
long((LPCREATESTRUCT(lParam))->lpCreateParams));
}
wnd = (WinHandle*) (::GetWindowLong(hwnd,GWL_USERDATA));
if (wnd)
return wnd->WndProc(msg,wParam,lParam);
else
return ::DefWindowProc(hwnd,msg,wParam,lParam);
}
由于此函数是 static ,因此没有 this 指针,并且它与 WNDCLASSEX 完美配合,但由于某种原因它从不调用 wnd->WndProc() 并始终返回默认的窗口过程。需要帮助。怎么了?有谁知道更好的方法?
I am writing a Windows Api wrapper and I have run into a problem. I am abstracting the Window Procedure (WndProc) and wrote a static MsgHandler which would call the WndProc of my WinHandler class. Here is the code:
LRESULT CALLBACK WinHandle::MsgHandler(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
WinHandle* wnd = 0;
if (msg == WM_NCCREATE)
{
::SetWindowLong(hwnd,GWL_USERDATA,
long((LPCREATESTRUCT(lParam))->lpCreateParams));
}
wnd = (WinHandle*) (::GetWindowLong(hwnd,GWL_USERDATA));
if (wnd)
return wnd->WndProc(msg,wParam,lParam);
else
return ::DefWindowProc(hwnd,msg,wParam,lParam);
}
Since this functions is static , there is no this pointer and it works perfectly with WNDCLASSEX, but for some reason it never calls wnd->WndProc() and always returns the default window procedure. Need Help. What is wrong? Does anyone know a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您收到 WM_CREATE 而不是 WM_NCCREATE 时调用 SetWindowLong。我认为 lpCreateParams 在 WM_NCCREATE 中无效。那是:
Call SetWindowLong when you receive WM_CREATE, not WM_NCCREATE. I don't think lpCreateParams is valid in WM_NCCREATE. That is: