visual-c++ - 如何使用 GDI+ 在 C++ 中更改常用控件(如按钮、标签等)的文本字体样式?
问题描述
我正在尝试使用 GDI+ 更改按钮的字体样式,但我不知道该怎么做。
我的按钮 -
HWND btn = CreateWindow(L"BUTTON", L"My button", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 50, 50, 100, 300, hWnd, NULL, NULL, NULL);
我已经初始化了 GDI+ -
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
并关闭它 -
GdiplusShutdown(gdiplusToken);
请提供任何帮助
解决方案
通用控件不使用 GDI+。你需要使用LOGFONT。
HWND TextBox;
TextBox = CreateWindowW(WC_EDIT, L"", WS_BORDER | WS_VISIBLE | WS_CHILD, 330, 130, 300, 100, hWnd, NULL, NULL, NULL);
LOGFONT logfont;
ZeroMemory(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = DEFAULT_CHARSET; //Font
logfont.lfHeight = 20; //Font Height
logfont.lfWidth = 23; //Font Width
logfont.lfWeight = 300; //Font Weight
//If want
logfont.lfItalic = true; // Italic (Boolean)
logfont.lfUnderline = true; // Underline (Boolean)
HFONT hFont = CreateFontIndirect(&logfont);
SendMessage(TextBox, WM_SETFONT, (WPARAM)hFont, TRUE);
推荐阅读
- php - array_push() 期望参数 1 是数组,int 给定
- azure-devops - 如何使用 REST API 更新 Azure DevOps Server 2019 中的当前阶段发布变量?
- angular - 如何使用 jasmine 和 karma 在前端 Angular 和后端节点的单元测试中发布和放置请求?
- git - 如何解决github上的合并冲突
- android - EXPO sdk39 中的应用通知设置访问
- php - 如何在 php 查询中更新和使用连接表?
- curl - cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书 XAMPP Wordpress
- amazon-web-services - AWS update-function-code 显示无输出且不更新函数
- php - Symfony,请求找不到服务
- c# - 致命错误 C1001:编译器发生内部错误。在 gcroot.h