I have this problem that drives me mad, so I am here to ask for your help. I have this code that is supposed to create a simple window and show it:
void ShowMainWindow() {
WNDCLASSEX main_window_class; // New window class for the splash window //
main_window_class.cbSize = sizeof(WNDCLASSEX); // Set size of the splash window class //
main_window_class.style = CS_PARENTDC|CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS; // Main window class style //
main_window_class.lpfnWndProc = MainProc; // Pointer to the main window procedure //
main_window_class.cbClsExtra = 0; // No extra bytes after class structure //
main_window_class.cbWndExtra = 0; // No extra bytes after window's instance //
main_window_class.hInstance = Instance; // Set instance of the window //
main_window_class.hIcon = LoadIcon(Instance, MAKEINTRESOURCE(MICON)); // Executable's icon //
main_window_class.hCursor = LoadCursor(NULL, IDC_ARROW); // Main window's default cursor //
main_window_class.hbrBackground = HBRUSH(COLOR_WINDOW + 1); // Main window's default background //
main_window_class.lpszClassName = L"MyAppClass"; // Main window's class name //
main_window_class.hIconSm = LoadIcon(Instance, MAKEINTRESOURCE(SICON)); // Application's small icon //
if (!RegisterClassEx(&main_window_class)) { // If the class was not registered //
MessageBox(NULL, L"RegisterClassEx", L"Error", MB_OK|MB_ICONERROR);
}
MainWindow = CreateWindowEx ( // Create the main window //
WS_EX_APPWINDOW, // Extended style to support transparency //
main_window_class.lpszClassName, // Assign the anterior class name //
(WCHAR*)"App Title", // Main window's title //
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, // No border window //
CW_USEDEFAULT, // Default left position for the moment //
CW_USEDEFAULT, // Default top position for the moment //
600, // Main window width //
400, // Main window height //
NULL, // No parent //
NULL, // No ID //
Instance, // Assign to main instance //
NULL // No additional data needed //
);
if (!MainWindow) { // If the window was not created //
MessageBox(NULL, L"CreateWindowEx", L"Error", MB_OK|MB_ICONERROR);
}
long Style = GetWindowLong(MainWindow, GWL_STYLE);
Style &= ~WS_MAXIMIZEBOX;
SetWindowLong(MainWindow, GWL_STYLE, Style);
ShowWindow(MainWindow, SW_SHOWNORMAL); // Display main window at normal size //
UpdateWindow(MainWindow); // Update the window's client area //}
My problem is that, when the window is opened, the title of the window is not “App Title” but some weird characters plus “CreateWindowEx“. It is so weird. It’s like it assigns that text from the MessageBox function to the title of the window. I must specifiy that I use UNICODE encoding. Anyway, it never happened to me before and I just don’t know what could be wrong. Thanks!
You can’t cast a
const char*to aWCHAR*.You need to replace
(WCHAR*)"App Title"withL"App Title".