C++ 使用 CreateWindowEx 制作仅消息窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4081334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:30:35  来源:igfitidea点击:

Using CreateWindowEx to Make a Message-Only Window

c++windowswinapi

提问by Jim Fell

I'm trying to use CreateWindowExto generate a message-only window:

我正在尝试用于CreateWindowEx生成仅消息窗口:

_hWnd = CreateWindowEx( 0, NULL, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );

When my application executes this line it always returns _hWnd = 0. What am I doing wrong?

当我的应用程序执行这一行时,它总是返回_hWnd = 0. 我究竟做错了什么?

回答by Kirill V. Lyadvinsky

lpClassNameshouldn't be NULL. Register class using RegisterClassExfunction and pass it to CreateWindowEx.

lpClassName不应该NULL。使用RegisterClassEx函数注册类并将其传递给CreateWindowEx.

static const char* class_name = "DUMMY_CLASS";
WNDCLASSEX wx = {};
wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = pWndProc;        // function which will handle messages
wx.hInstance = current_instance;
wx.lpszClassName = class_name;
if ( RegisterClassEx(&wx) ) {
  CreateWindowEx( 0, class_name, "dummy_name", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
}

回答by Cheers and hth. - Alf

According to the Microsoft docsthe class name should be "Message".

根据Microsoft 文档,类名应该是“Message”。

Cheers & hth.,

干杯 & hth.,