gpt4 book ai didi

c++ - 创建的窗口没有标题

转载 作者:太空狗 更新时间:2023-10-29 22:57:56 25 4
gpt4 key购买 nike

<分区>

我正在从我的控制台应用程序创建消息窗口。窗口类已正确注册并且窗口已正确创建,但它从来没有标题(而我的 createwindow 函数调用确实指定了标题)。让我思考,控制台程序可以创建带有名称的窗口吗?谷歌了一下,一无所获。这是我的代码,保持在最低限度:

using namespace std;
hInstance = GetModuleHandle(NULL);
WNDCLASS WndClass = {};
WndClass.style = CS_HREDRAW | CS_VREDRAW; // == 0x03
WndClass.lpfnWndProc = pWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hIcon = 0;
WndClass.hCursor = 0;
WndClass.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "EME.LauncherWnd";
int style = WS_OVERLAPPED | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU | WS_THICKFRAME | WS_CAPTION;
if (RegisterClassA(&WndClass))
{
cout << "class registered. Hinstance : " << hInstance << " style : (expect 0xcf0000) " << std::hex << style << endl;
HWND hwind2 = CreateWindowExA(0, "EME.LauncherWnd", "Mytitle", style, 0x80000000, 0x80000000, 0x80000000, 0x80000000, NULL, NULL, hInstance, NULL);
if (hwind2 == 0)
cout << "Couldn't create window" << endl;
else
cout << "created window" << endl;
}

输出:

class registered. Hinstance : 00E40000
created window

检查 Nirsoft 的 Winlister,窗口存在,具有正确的类(“EME.LauncherWnd”),但没有名称。此外,在 block 中添加这些代码行:

if (0 == SetWindowText(hwind2, "aTitle"))
cout << "couldn't set a title" << endl;
else
cout << "title set " << endl;

输出是

title set

然而,窗口仍然没有标题。如果控制台程序没有标题,我会假设 SetWindowText 调用将返回 0。我究竟做错了什么 ?编辑:根据要求添加 pWndProc

LRESULT CALLBACK pWndProc(HWND hwnd,            // Handle to our main window
UINT Msg, // Our message that needs to be processed
WPARAM wParam, // Extra values of message
LPARAM lParam) // Extra values of message
{
switch (Msg)

{
case WM_DESTROY:
....
break;
}
}

尽管在注释指出 pWndProc(我认为它与窗口的构造无关)之后,结果是将此代码行作为默认值插入 switch case

return DefWindowProc(hwnd, Msg, wParam, lParam);

解决问题。

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