CreateWindow 由于无法找到窗口类而失败 - C++
在我的应用程序中,函数 CreateWindow
由于某种原因失败。 GetLastError
表示错误 1407,根据 MSDN 文档,该错误是“找不到窗口类”。以下代码显示了如何调用 CreateWindow 以及调用时的相应变量名称:
m_hInstance = ::GetModuleHandle( NULL );
if ( m_hInstance == NULL )
{
TRACE(_T("CNotifyWindow::CNotifyWindow : Failed to retrieve the module handle.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
THROW(::GetLastError());
}
m_hWnd = ::CreateWindow(
_pwcWindowClass, // L"USBEventNotificationWindowClass"
_pwcWindowName, // L"USBEventNotificationWindow"
WS_ICONIC,
0,
0,
CW_USEDEFAULT,
0,
NULL,
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.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
THROW(::GetLastError());
}
::ShowWindow( m_hWnd, SW_HIDE );
我做错了什么?
In my application the function CreateWindow
is failing for some reason. GetLastError
indicates error 1407, which, according to the MSDN documentation is "Cannot find window class." The following code shows how CreateWindow
is being called and the respective variables names at time of call:
m_hInstance = ::GetModuleHandle( NULL );
if ( m_hInstance == NULL )
{
TRACE(_T("CNotifyWindow::CNotifyWindow : Failed to retrieve the module handle.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
THROW(::GetLastError());
}
m_hWnd = ::CreateWindow(
_pwcWindowClass, // L"USBEventNotificationWindowClass"
_pwcWindowName, // L"USBEventNotificationWindow"
WS_ICONIC,
0,
0,
CW_USEDEFAULT,
0,
NULL,
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.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
THROW(::GetLastError());
}
::ShowWindow( m_hWnd, SW_HIDE );
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须先调用 RegisterClassEx 才能使用窗口类在创建窗口上。
示例代码此处。
You have to call RegisterClassEx before you can use the window class on CreateWindow.
Example code here.