为对话框创建窗口类 [英] Creating window class for Dialog

查看:121
本文介绍了为对话框创建窗口类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为对话框窗口创建了带有静态窗口proc的窗口类,并在创建窗口时执行了一个错误:写入位置"0x00000000"时访问被拒绝

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);

和窗口proc功能:

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));

    // ...
}

推荐答案

对话框的第一条消息"为

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).

这篇关于为对话框创建窗口类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆