c++ - CreateWindow 因无法找到窗口类而失败 - C++

标签 c++ visual-studio-2008 createwindow

在我的应用程序中,函数 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 );

我做错了什么?

最佳答案

你必须调用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.

关于c++ - CreateWindow 因无法找到窗口类而失败 - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4306630/

相关文章:

c++ - 如何为 map < map<int,int> , bool > 赋值?

c++ - 处理连续 block 与非连续内存块时的效率

visual-studio-2008 - 带有 SQL Server 2008 的 SQL 数据库发布向导

c++ - 如何正确销毁从另一个线程运行的窗口?

c++ - InitCommonControlsEx() 在 Windows 8.1 中因 ICC_LINK_CLASS 而失败

c++ - 对话框窗口重新初始化问题

c++ - 运算符不匹配 == 错误,C++

c++ - LLVM GetAnalysis() 因所需的传递而失败

visual-studio-2008 - 如何在 SQL 中截断表值参数 (TVP)?

visual-studio - 源代码与原始版本不同