导语:在封装一个基本的Frame显示窗口时遇到CreateWindow函数调用成功,但是窗口总是不显示。
CreateWindow返回NULL,GetLastError()返回0
经过网上搜集资料和单步调试发现问题
在程序调用CreateWindow函数之前会首先调用WndProc具体原因暂时不详,(我的程序这里好像是会调用三次WndProc,可能是系统发送的消息),然后会调用CreateWindow,所以当前几次调用WndProc时需要返回TURE才会成功创建window。
这是之前的WndProc函数代码
LRESULT CALLBACK MYFrame::__WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MYFrame *pObj = ( MYFrame *)::GetWindowLong( hWnd, GWL_USERDATA); PAINTSTRUCT ps; HDC hdc; long xPos; long yPos; switch( uMsg ) { case WM_PAINT: hdc = ::BeginPaint(hWnd, &ps); ::EndPaint(hWnd, &ps); break; case WM_DESTROY: ::PostQuitMessage(0); break; default: ::DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; }将
default: ::DefWindowProc(hWnd, uMsg, wParam, lParam);
default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
LRESULT CALLBACK MYFrame::__WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MYFrame *pObj = ( MYFrame *)::GetWindowLong( hWnd, GWL_USERDATA); PAINTSTRUCT ps; HDC hdc; long xPos; long yPos; switch( uMsg ) { case WM_PAINT: hdc = ::BeginPaint(hWnd, &ps); ::EndPaint(hWnd, &ps); break; case WM_DESTROY: ::PostQuitMessage(0); break; default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; }