如何使用 GDI+ 在 C++ 中更改按钮、标签等常用控件的文本字体样式?
How to change the font style of the text of a common control like button, label, etc. in c++ using GDI+?
我正在尝试使用 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);
我正在尝试使用 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);