gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:23:35 26 4
gpt4 key购买 nike

#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

关于c - 为什么在字体对话框中不显示 SYSTEM_FONT 的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29980025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com