Moderators Melba23 Posted November 13, 2008 Moderators Posted November 13, 2008 (edited) 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 November 13, 2008 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
LarryDalooza Posted November 13, 2008 Posted November 13, 2008 I thought that by, default AutoIt, uses the default font. It does the API calls that you are looking for. I thought. Lar. AutoIt has helped make me wealthy
Moderators Melba23 Posted November 13, 2008 Author Moderators Posted November 13, 2008 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
LarryDalooza Posted November 13, 2008 Posted November 13, 2008 (edited) 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. expandcollapse popup#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 November 13, 2008 by LarryDalooza pixelsearch 1 AutoIt has helped make me wealthy
Moderators Melba23 Posted November 13, 2008 Author Moderators Posted November 13, 2008 (edited) @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 November 13, 2008 by Melba23 pixelsearch 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
wraithdu Posted November 13, 2008 Posted November 13, 2008 What about _WinAPI_GetStockObject($DEFAULT_GUI_FONT)? I'm away from my dev computer, so I don't remember if the constant name is exactly right, but it's the basic idea.
LarryDalooza Posted November 13, 2008 Posted November 13, 2008 What about _WinAPI_GetStockObject($DEFAULT_GUI_FONT)?I'm away from my dev computer, so I don't remember if the constant name is exactly right, but it's the basic idea.That is very common... but the msdn recommends SystemParametersInfo... whatevsLar. AutoIt has helped make me wealthy
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now