提问人:cf404 提问时间:11/15/2023 最后编辑:IInspectablecf404 更新时间:11/15/2023 访问量:159
不理解 C++ 窗口中的字符
Don't understand the characters in C++ window
问:
我有一个基本项目,它应该打开一个空白窗口,名称为“是”。相反,我得到了这些奇怪的外来符号。不久前,我看到其他几个人报告了同样的问题。我是 C++ 的新手,所以也许它很简单?我的 IDE 中没有任何错误,并且我正在使用 Visual Studio。
#include <windows.h>
bool running = true;
void* buffer_memory;
BITMAPINFO buffer_bitmap_info;
LRESULT CALLBACK window_callback(HWND hwnd, UINT uMSG, WPARAM wParam, LPARAM lParam) {
LRESULT result = 0;
switch (uMSG) {
case WM_CLOSE:
case WM_DESTROY: {
running = false;
} break;
case WM_SIZE: {
RECT rect;
GetClientRect(hwnd, &rect);
int buffer_width = rect.right - rect.left;
int buffer_height = rect.bottom - rect.top;
int buffer_size = buffer_width * buffer_height * sizeof(unsigned int);
if (buffer_memory) VirtualFree(buffer_memory, 0, MEM_RELEASE);
buffer_memory = VirtualAlloc(0, buffer_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
buffer_bitmap_info.bmiHeader.biSize = sizeof(buffer_bitmap_info.bmiHeader);
buffer_bitmap_info.bmiHeader.biWidth = buffer_width;
buffer_bitmap_info.bmiHeader.biHeight = -buffer_height;
buffer_bitmap_info.bmiHeader.biPlanes = 1;
buffer_bitmap_info.bmiHeader.biBitCount = 32;
buffer_bitmap_info.bmiHeader.biCompression = BI_RGB;
} break;
default: {
result = DefWindowProc(hwnd, uMSG, wParam, lParam);
}
}
return result;
}
int main() {
return WinMain(GetModuleHandle(NULL), NULL, GetCommandLineA(), SW_SHOW);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
// Create Window Class
WNDCLASSA window_class = {};
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.lpszClassName = "Game_Window_Class";
window_class.lpfnWndProc = window_callback;
// Register Class
RegisterClassA(&window_class);
// Create Window
CreateWindowA(window_class.lpszClassName, "Yes", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 1920, 1080, 0, 0, hInstance, 0);
while (running) {
// Input
MSG message;
while (PeekMessageA(&message, 0, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageA(&message);
}
// Simulate
// Render
}
return 0;
}
我以为名字是“是”,而不是图像上的名字。它唯一不放置符号的时间是当我使用一个字母时。
答: 暂无答案
评论
A
TEXT()
(LPCSTR)L"Yes"