为什么在字体对话框中不显示 SYSTEM_FONT 的字体大小?

Why doesn't font size show for SYSTEM_FONT in Font dialog?

#include <windows.h>


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_RBUTTONUP:
        {
            HFONT hFont;
            LOGFONT lf;
            CHOOSEFONT cf = {0};

            hFont = (HFONT)GetStockObject(SYSTEM_FONT);
            GetObject(hFont, sizeof(LOGFONT), &lf);

            cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
            cf.hwndOwner = hwnd;
            cf.lpLogFont = &lf;
            cf.lStructSize = sizeof(CHOOSEFONT);

            if(ChooseFont(&cf))
            {
            }
        }
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
    WNDCLASSEX wc = {0};
    HWND hwnd;
    MSG msg;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = L"MainClass";

    if(!RegisterClassEx(&wc))
        return 0;

    hwnd = CreateWindowEx(0, wc.lpszClassName, L"First", WS_OVERLAPPEDWINDOW,
        50, 30, 400, 200, 0, 0, hInstance, 0);

    if(!hwnd)
        return 0;

    ShowWindow(hwnd, nShowCmd);

    while(GetMessage(&msg, 0, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;


}

字体对话框中大小组合框的编辑框中没有显示正确的字体大小。这是在 windows xp sp3 中测试的。不知道在其他操作系统中是否会发生这种情况。为什么没有显示正确的字体大小?

SYSTEM_FONT 似乎是 Microsoft 多年未使用的损坏常量,它指向的字体不是 TrueType 或 OpenType。 SYSTEM_FONTDEFAULT_GUI_FONT 已经很老了,几乎肯定会被弃用;我建议您不要使用它们。

来自 GetStockObject 的文档:

It is not recommended that you employ this method to obtain the current font used by dialogs and windows. Instead, use the SystemParametersInfo function with the SPI_GETNONCLIENTMETRICS parameter to retrieve the current font. SystemParametersInfo will take into account the current theme and provides font information for captions, menus, and message dialogs.

它还说:

It is not recommended that you use DEFAULT_GUI_FONT or SYSTEM_FONT to obtain the font used by dialogs and windows.

另见 http://weblogs.asp.net/kdente/394499