今天创建窗口的时候,在捕获消息WM_CREATE的时候翻车了,找了好久都没找到,我换另一台电脑上又没出问题,
现分享下:
LRESULT QWnd::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (WM_CREATE == uMsg) { //就是这里,在创建的时候传进来一个this指针,我给写成了 //QWnd* pWnd = (QWnd*)(LPCREATESTRUCT)lParam; //我晕了好久, QWnd* pWnd = (QWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams; if (pWnd) { pWnd->m_hWnd = hWnd; SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG)pWnd); } } QWnd* pWnd = (QWnd*)GetWindowLongPtr(hWnd, GWL_USERDATA); if (pWnd) { const MSGSTRUCT* pMs = pWnd->FindMsg(uMsg,wParam); if (pMs != NULL) { return (pWnd->*(pMs->pfn))(wParam, lParam); } } return DefWindowProc(hWnd, uMsg, wParam, lParam); }
老是出现访问冲突,又找不到哪冲突.晕死了半天.