使用 CreateWindowEx 制作仅消息窗口

2021-12-18 00:00:00 windows winapi c++

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

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

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

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

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

推荐答案

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

lpClassName shouldn't be NULL. Register class using RegisterClassEx function and pass it to 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 );
}

相关文章