Gui/system default font

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 726
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: 2453
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
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] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 6464
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: 726
Joined: 29 Sep 2013, 22:18

Re: Gui/system default font

16 Mar 2015, 07:50

Thank you both - more complicated than I imagined.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], effel, MannyKSoSo and 176 guests