Window Procedure Not Being Called By Message Handler
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 lPar开发者_运维问答am)
{
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?
Call SetWindowLong when you receive WM_CREATE, not WM_NCCREATE. I don't think lpCreateParams is valid in WM_NCCREATE. That is:
if (msg == WM_CREATE)
{
::SetWindowLong(hwnd,GWL_USERDATA,
long((LPCREATESTRUCT(lParam))->lpCreateParams));
}
精彩评论