MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ControlSetFont

Method ControlSetFont

source/script_gui.cpp:1223–1254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1221
1222
1223ResultType GuiType::ControlSetFont(GuiControlType &aControl, LPTSTR aOptions, LPTSTR aFontName)
1224{
1225 if (!aControl.UsesFontAndTextColor()) // Control has no use for a font.
1226 return g_script.RuntimeError(ERR_GUI_NOT_FOR_THIS_TYPE);
1227 COLORREF color = CLR_INVALID;
1228 int font_index;
1229 if (*aOptions || *aFontName) // Use specified font.
1230 {
1231 FontType font;
1232 // Get control's current font, to inherit attributes.
1233 font.hfont = (HFONT)SendMessage(aControl.hwnd, WM_GETFONT, 0, 0);
1234 FontGetAttributes(font);
1235
1236 // Find or create font with the changed attributes.
1237 font_index = FindOrCreateFont(aOptions, aFontName, &font, &color);
1238 if (font_index == -1)
1239 return FAIL;
1240 }
1241 else // Use GUI's current font.
1242 {
1243 font_index = mCurrentFontIndex;
1244 // It seems more correct to leave the control's current color, since there's
1245 // no way to know whether it should take precedence over the GUI's text color.
1246 // Require the caller to be explicit and specify the color if it should be changed.
1247 //color = mCurrentColor;
1248 }
1249 SendMessage(aControl.hwnd, WM_SETFONT, (WPARAM)sFont[font_index].hfont, 0);
1250 if (color != CLR_INVALID)
1251 ControlSetTextColor(aControl, color);
1252 ControlRedraw(aControl, false); // Required for refresh, at least for edit controls, probably some others.
1253 return OK;
1254}
1255
1256
1257void GuiType::ControlSetTextColor(GuiControlType &aControl, COLORREF aColor)

Callers 1

InvokeMethod · 0.80

Calls 2

UsesFontAndTextColorMethod · 0.80
RuntimeErrorMethod · 0.80

Tested by

no test coverage detected