I am creating messages windows from my console application. The window class is registered correctly and the window is created correctly however it never has a title (while my createwindow function call does specify a title). Got me thinking, can console programs create windows with name? Googled it, found nothing. This is my code, kept to the minimum :
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;
}
output :
class registered. Hinstance : 00E40000
created window
Checking with Nirsoft's Winlister, the window exists, has the right class ("EME.LauncherWnd"), but has no name. furthermore, adding these lines of code in the block :
if (0 == SetWindowText(hwind2, "aTitle"))
cout << "couldn't set a title" << endl;
else
cout << "title set " << endl;
The output is
title set
And yet, the window still doesn't have a title. If console program couldn't have title I'd assume the SetWindowText call would return 0. What am I doing wrong ? Edit : Adding pWndProc as requested
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;
}
}
Though after the comment pointing out the pWndProc (which body i thought was irrelevant to the construction of the window), it turns out inserting this code line as a default in the switch case
return DefWindowProc(hwnd, Msg, wParam, lParam);
solves the problem.