我使用CreateWindowExA来创建窗口.为什么我的窗口标题文本显示为多字节编码?

Kos*_*mos 2 c++ windows winapi

我有这个程序:

#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CLOSE:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }

    return 0;
}

int main()
{
    WNDCLASSA wnd_class = { 0 }; 
    wnd_class.lpfnWndProc = WndProc;
    wnd_class.hInstance = GetModuleHandle(NULL);
    wnd_class.lpszClassName = "actwnd";

    RegisterClassA(&wnd_class);

    HWND main_wnd = CreateWindowA(wnd_class.lpszClassName, "Program activation", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, NULL, 0, wnd_class.hInstance, NULL);

    MSG msg = { 0 };
    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么Window标题显示不正确:

在此输入图像描述

看起来对于我来说未知的原因,有些东西仍然认为这是unicode两字节编码...

文件高级保存选项编码设置为单字节1 - 赢1251.

我想使用完全ANSI版本,我的窗口标题只包含ANSI字符.

Dav*_*nan 7

您的窗口过程需要调用DefWindowProcA.

  • 没有错误,因为`DefWindowProc`不接收字符类型的参数.但是角色数据确实通过窗口过程并且必须由强制转换访问.因此,它无法进行类型检查. (2认同)