Jump to content

[SOLVED] Finding Default System Fonts


Melba23
 Share

Recommended Posts

  • Moderators

Hi,

I am trying to determine what default font is used by Windows for message boxes. I want to get my dialogs using the same font to improve the "look and feel" of my application.

I have managed to find a registry key HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics: MessageFont which produces the expected "Segoe UI" (I am running Vista), but the font size does not seem to be recorded anywhere nearby. As Control Panel allows you to change both the font and size for message boxes, it must store the results somewhere.

I also looked at various API calls on MSDN, but the only one that seemed likely was the NONCLIENTMETRICS structure, which gives "A pointer to a LOGFONT structure that contains information about the font used in message boxes". However, as MSDN has no information on the LOGFONT structure, it looks like a dead-end. And I am not that experienced at coding structs anyway!

So, any ideas or solutions? Thanks in advance.

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Sorry, I should have been more specific.

As you stated, AutoIt does use the default fonts in things like message boxes, but the app I am writing uses some custom GUIs where the user can choose the font and size. In particular, a scrolling marquee text (based on something I found on the forums lately). This uses object type variables to define most of the GUI and I want to reset the font to default values as one of the options. At the moment I have it hard coded based on the normal Vista message font, but as you can change this in Control Panel, I wondered if there was a way to find out if the user had indeed altered it.

As I said earlier, it is a 'look and feel' issue - the code works nicely with the hard coded values, but I wanted to add a bit extra if I could. If I cannot, it is not the end of the world. However, as AutoIt apparently does it, I thought it must be possible!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I am not very good at DLLStructCreate... and I have not much time... but this is some SystemParametersInfo stuff from microsoft that is supposed to return the info you want... somone else might fix it.

#cs
typedef struct tagNONCLIENTMETRICS {
  UINT cbSize;
  int iBorderWidth;
  int iScrollWidth;
  int iScrollHeight;
  int iCaptionWidth;
  int iCaptionHeight;
  LOGFONT lfCaptionFont;
  int iSmCaptionWidth;
  int iSmCaptionHeight;
  LOGFONT lfSmCaptionFont;
  int iMenuWidth;
  int iMenuHeight;
  LOGFONT lfMenuFont;
  LOGFONT lfStatusFont;
  LOGFONT lfMessageFont;
#if (WINVER >= 0x0600)
  int iPaddedBorderWidth;
#endif 
} NONCLIENTMETRICS, 
 *LPNONCLIENTMETRICS;
 
 typedef struct tagLOGFONT { 
  LONG lfHeight; 
  LONG lfWidth; 
  LONG lfEscapement; 
  LONG lfOrientation; 
  LONG lfWeight; 
  BYTE lfItalic; 
  BYTE lfUnderline; 
  BYTE lfStrikeOut; 
  BYTE lfCharSet; 
  BYTE lfOutPrecision; 
  BYTE lfClipPrecision; 
  BYTE lfQuality; 
  BYTE lfPitchAndFamily; 
  TCHAR lfFaceName[LF_FACESIZE]; 
} LOGFONT, *PLOGFONT; 
#ce

$nonclientmetrics = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
DLLStructSetData($nonclientmetrics,1,DllStructGetSize($nonclientmetrics))

Global Const $SPI_GETNONCLIENTMETRICS = 41

$a = DLLCall("user32.dll","int","SystemParametersInfo","int",41, _
        "int",DllStructGetSize($nonclientmetrics), _
        "ptr",DllStructGetPtr($nonclientmetrics),"int",0)

$b = DLLCall("kernel32.dll","int","GetLastError")

MsgBox(4096,$b[0],$a[0])

$logfont1 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]",DLLStructGetPtr($nonclientmetrics,7))
$logfont2 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]",DLLStructGetPtr($nonclientmetrics,10))
$logfont3 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]",DLLStructGetPtr($nonclientmetrics,13))
$logfont4 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]",DLLStructGetPtr($nonclientmetrics,14))
$logfont5 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]",DLLStructGetPtr($nonclientmetrics,15))

MsgBox(4096,"",DllStructGetData($logfont1,14) & @LF & _
        DllStructGetData($logfont2,14) & @LF & _
        DllStructGetData($logfont3,14) & @LF & _
        DllStructGetData($logfont4,14) & @LF & _
        DllStructGetData($logfont5,14))

Lar.

Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

  • Moderators

@Lar,

Thanks a lot - it looks as if it could be the answer.

I get answers to the following:

DllStructGetData($logfont1, 1) - might be the point size, although -12 seems a bit odd

DllStructGetData($logfont1, 5) - reads 400 and so looks like the weight (as in GUICtrlSetFont) and

DllStructGetData($logfont1, 14) - is the font name.

I will play with the -12 answer a bit and see if I can get anywhere. And also look into your struct code to see if I can learn more about that side of things.

Thanks again,

M23

Edit:

Yes, -12 is basically a point value. For normal fonts the point size is .75 of this value (based on a wonderful calculation using dots per inch and points per inch). It is negative for some internal Windows font mapping ID reason.

So again thanks for a complete solution.

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...