CreateWindow 由于无法找到窗口类而失败 - C++

发布于 2024-10-05 05:05:24 字数 1051 浏览 1 评论 0原文

在我的应用程序中,函数 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2024-10-12 05:05:24

您必须先调用 RegisterClassEx 才能使用窗口类在创建窗口上。

示例代码此处

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

You have to call RegisterClassEx before you can use the window class on CreateWindow.

Example code 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文