C ++ pointers issue affecting window title

I have this problem that drives me crazy, so I'm here to ask for your help. I have this code that should 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 instance    //
main_window_class.hInstance      = Instance;                                                 // Set instance of the window                //
main_window_class.hIcon          = LoadIcon(Instance, MAKEINTRESOURCE(MICON));               // Executable icon                         //
main_window_class.hCursor        = LoadCursor(NULL, IDC_ARROW);                              // Main window default cursor              //
main_window_class.hbrBackground  = HBRUSH(COLOR_WINDOW + 1);                                 // Main window default background          //
main_window_class.lpszClassName  = L"MyAppClass";                                            // Main window class name                  //
main_window_class.hIconSm        = LoadIcon(Instance, MAKEINTRESOURCE(SICON));               // Application 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 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 client area           //}

My problem is that when I open the window, the window title is not “Application Name”, but some strange characters plus “CreateWindowEx”. This is so strange. It looks like this text from the MessageBox function is assigned to the window title. I must indicate that I am using UNICODE encoding. In any case, this has never happened to me before, and I just don’t know what might be wrong. Thank!

+3
source share
2 answers

const char* WCHAR*.

(WCHAR*)"App Title" L"App Title".

+3

(WCHAR*)"App Title" . "App Title" - ANSI, Unicode Windows API, CreateWindowEx WCHAR *, .. Unicode.

- L"App Title"; L , (~ Unicode) "" .

, "" , , const WCHAR_T *, . ; , , , , , t . " " .

ANSI ( , ) Unicode, .

: .

+6

All Articles