我从我的控制台应用程序创建消息窗口。窗口类被正确注册并且窗口被正确创建,但是它从来没有标题(而我的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”),但无名。 此外,添加这些行的代码块中的:
if (0 == SetWindowText(hwind2, "aTitle"))
cout << "couldn't set a title" << endl;
else
cout << "title set " << endl;
输出是
title set
然而,窗口仍然没有标题。如果控制台程序不能有标题,我会假设SetWindowText调用将返回0. 我做错了什么? 编辑:如请求
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(我认为哪个机构无关的窗口的结构)后添加pWndProc,原来插入这个代码行作为所述开关的默认案例
return DefWindowProc(hwnd, Msg, wParam, lParam);
解决了这个问题。
“*可以控制台程序创建窗口名称?*” - 当然,是的。终端本身只是一个普通的Win32应用程序。控制台应用程序可以完全访问Win32 API。这就是说,pWndProc指的是什么,它正确地处理窗口消息? –
u nead a massage loop –
投票结束,因为缺乏可重复的例子。 –