我有这个让我发疯的问题,所以我在这里寻求您的帮助。我有这段代码应该创建一个简单的窗口并显示它:
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 //}
我的问题是,当窗口打开时,窗口的标题不是“App Title”而是一些奇怪的字符加上“ CreateWindowEx ”。太奇怪了。就像它将 MessageBox 函数中的文本分配给窗口的标题一样。我必须指定我使用 UNICODE 编码。无论如何,它以前从未发生在我身上,我只是不知道可能出了什么问题。谢谢!