加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

CreateWindow因无法找到窗口类而失败 – C

发布时间:2020-12-16 09:31:02 所属栏目:百科 来源:网络整理
导读:在我的应用程序中,CreateWindow函数由于某种原因失败. GetLastError指示错误1407,根据MSDN文档,“无法找到窗口类”.以下代码显示了如何调用CreateWindow以及调用时的相应变量名称: m_hInstance = ::GetModuleHandle( NULL );if ( m_hInstance == NULL ){ TR
在我的应用程序中,CreateWindow函数由于某种原因失败. GetLastError指示错误1407,根据MSDN文档,“无法找到窗口类”.以下代码显示了如何调用CreateWindow以及调用时的相应变量名称:

m_hInstance = ::GetModuleHandle( NULL );

if ( m_hInstance == NULL )
{
    TRACE(_T("CNotifyWindow::CNotifyWindow : Failed to retrieve the module handle.rntError: %drntFile: %srntLine: %drn"),::GetLastError(),__WFILE__,__LINE__);
    THROW(::GetLastError());
}

m_hWnd = ::CreateWindow(
    _pwcWindowClass,// L"USBEventNotificationWindowClass"
    _pwcWindowName,// L"USBEventNotificationWindow"
    WS_ICONIC,CW_USEDEFAULT,NULL,m_hInstance,// 0x00400000
    NULL
    );

if ( m_hWnd == NULL )   // m_hWnd is returned as NULL and exception is thrown.
{
    TRACE(_T("CNotifyWindow::CNotifyWindow : Failed to create window.rntError: %drntFile: %srntLine: %drn"),__LINE__);
    THROW(::GetLastError());
}

::ShowWindow( m_hWnd,SW_HIDE );

我究竟做错了什么?

解决方法

您必须先调用 RegisterClassEx才能在CreateWindow上使用窗口类.

示例代码here.

Each process must register its own window classes. To register an application local class,use the RegisterClassEx function. You must define the window procedure,fill the members of the WNDCLASSEX structure,and then pass a pointer to the structure to the RegisterClassEx function.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读