gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:18:21 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com