Gui/system default font

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Gui/system default font

16 Mar 2015, 01:04

How to determine what the default font is on a system or restore a gui to the default font after having set a font? Thanks
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Gui/system default font

16 Mar 2015, 02:05

Here is a function by SKAN (modiefied by me) to find out the Default Font and Font Size

Code: Select all

GuiDefaultFont() ; by SKAN (modified by jNizM)
{
    hFont := DllCall("gdi32.dll\GetStockObject", "Int", 17, "Ptr")
    VarSetCapacity(LF, szLF := 60 * (A_IsUnicode ? 2 : 1))
    DllCall("gdi32.dll\GetObject", "Ptr", hFont, "Int", szLF, "Ptr", &LF)
    hDC := DllCall("user32.dll\GetDC", "Ptr", hwnd), DPI := DllCall("gdi32.dll\GetDeviceCaps", "Ptr", hDC, "Int", 90)
    DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC), S := Round((-NumGet(LF, 0, "Int") * 72) / DPI)
	Fnt := {}, Fnt.Name := DllCall("kernel32.dll\MulDiv", "Int", &LF+28, "Int", 1, "Int", 1, "Str"), Fnt.Size := S
    return Fnt
}

MsgBox % "Font Name:`t" GuiDefaultFont().Name "`nFont Size:`t" GuiDefaultFont().Size
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9527
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui/system default font

16 Mar 2015, 03:14

My 'modernized' version:

Code: Select all

GuiDefaultFont() { ; by SKAN (modified by just me)
   VarSetCapacity(LF, szLF := 28 + (A_IsUnicode ? 64 : 32), 0) ; LOGFONT structure
   If DllCall("GetObject", "Ptr", DllCall("GetStockObject", "Int", 17, "Ptr"), "Int", szLF, "Ptr", &LF)
      Return {Name: StrGet(&LF + 28, 32), Size: Round(Abs(NumGet(LF, 0, "Int")) * (72 / A_ScreenDPI), 1)
            , Weight: NumGet(LF, 16, "Int"), Quality: NumGet(LF, 26, "UChar")}
   Return False
}

GuiFont := GuiDefaultFont()

MsgBox, 0, Default GUI Font, % "GuiFont:`t`t" GuiFont.Name "`nFontSize:`t`t" GuiFont.Size
                            . "`nFontWeight:`t" GuiFont.Weight "`nFontQuality:`t" GuiFont.Quality
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Gui/system default font

16 Mar 2015, 07:50

Thank you both - more complicated than I imagined.
User avatar
mslonik
Posts: 145
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: Gui/system default font

14 Feb 2021, 16:38

Thank you, too. I've found your code, as well as original code by SKAN and tested it a bit.

My question is: how to check the current system font size and font name?

The code provided above seems to show only the default font name and font size. If I change e.g. font size (Windows 10 -> Settings -> Ease of Access -> Display -> Make text bigger) it still shows default values.

Kind regards, mslonik (🐘)

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: kashmirLZ and 114 guests