Creating window class for Dialog

北战南征 提交于 2019-12-11 08:23:41

问题


I create a window class with static window proc for dialog window and have an error executed when window is creating: access denied when writing location "0x00000000"

// ... Creating window
_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc, (LPARAM)this);

And window proc function:

static INT_PTR CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    MainWindow * wnd = NULL;

    if(message == WM_NCCREATE) {

         wnd = reinterpret_cast<MainWindow *>(((LPCREATESTRUCT)lParam)->lpCreateParams);
         ::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<long>(wnd));
         wnd->_hWnd = hWnd;

    } else
         wnd = reinterpret_cast<MainWindow *>(::GetWindowLongPtr(hWnd, GWLP_USERDATA));

    // ...
}

回答1:


A dialog's "first message" is WM_INITDIALOG rather than WM_NCCREATE. The user data param is passed directly as the lParam value (rather than via a LPCREATESTRUCT pointed to by lParam).



来源:https://stackoverflow.com/questions/21658656/creating-window-class-for-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!