代码之家  ›  专栏  ›  技术社区  ›  Jim Fell

CreateWindow无法找到窗口类-C++

  •  3
  • Jim Fell  · 技术社区  · 15 年前

    在我的应用程序中 CreateWindow 因为某种原因失败了。 GetLastError 指示错误1407,根据msdn文档,该错误为“找不到窗口类”。下面的代码显示了如何 创建窗口 正在调用,调用时各个变量名:

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

    我做错什么了?

    1 回复  |  直到 15 年前
        1
  •  7
  •   Steve Townsend    15 年前

    你得打电话 RegisterClassEx 在CreateWindow上使用Window类之前。

    示例代码 here .

    每个进程必须注册自己的进程 窗口类。注册一个 应用程序本地类,使用 RegisterClassEx函数。你必须 定义窗口过程,填充 wndclassex结构的成员, 然后将指针传递给 寄存器ClassEx的结构 功能。