This way I want to recognize the Windows system font (currently used by the user on his desktop) and use this setting as reference/base for loading the same font in different (larger/smaller) sizes.
For testing purposes I've combined a small code for receiving the Windows system font (giving on my Win8.1 "Segoe UI" in sizes 16, 12, 12 if I output all values of the WinAPI functions), thanksfully taken from the posting of 'rashad' here: http://www.purebasic.fr/english/viewtop ... nt#p339231, with the first example code in the PB manual at the OpenXMLDialog() function.
My problem is, that using the values of this WinAPI functions the received font heights are much higher, causing a much larger display of my created Dialog window, as it should be. To see the effect, just commend the 'SetGadgetFont(...)' line in the test code.
Anyone knows what I must exactly do, to get the correct Windows font sizes I need to use for my own Dialogs/GUI's?
Btw. according to the MSDN article about 'Fonts' (see: https://msdn.microsoft.com/en-us/library/dn742483.aspx) I should use a WinAPI function GetThemeFont(...) !? In the 'Guidelines' chapter there is described "Segoe UI, 9 pixel" as the setting for 'standard text'... => now the question is: how to get this data from the system (as the user can have set another font / size on his Windows)??
Beside this: Is there any (cross-platform, for Windows+MacOS) way to adjust the Menu and Requester fonts, so that they also use the system font settings? (see the WinAPI function or the MSDN article, there are several possible font sizes... which can also be received)
Code: Select all
; Code for receiving the Windows system font (posting by 'rashad') taken from:
; http://www.purebasic.fr/english/viewtopic.php?f=13&t=44341&p=339231&hilit=systemfont#p339231
;
; More informations about the different Windows system fonts can be found in this MSDN article:
; https://msdn.microsoft.com/en-us/library/dn742483.aspx
spinfo.NONCLIENTMETRICS
spinfo\cbSize = SizeOf(spinfo)
SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, 0, @spinfo, 0)
Font$ = PeekS(@spinfo\lfCaptionFont\lfFaceName[0])
;Debug PeekS(@spinfo\lfSMCaptionFont\lfFaceName[0])
;Debug PeekS(@spinfo\lfMenuFont\lfFaceName[0])
;Debug PeekS(@spinfo\lfMessageFont\lfFaceName[0])
;FontHeight = - PeekL(@spinfo\lfCaptionFont\lfHeight) - 3
;FontHeight = - PeekL(@spinfo\lfMenuFont\lfHeight) - 3
FontHeight = - PeekL(@spinfo\lfMessageFont\lfHeight) - 3
LoadFont(0, Font$, FontHeight)
SetGadgetFont(#PB_Default, FontID(0)) ; <====== comment this and you will see a much smaller font used in the following Dialog!
CompilerIf #PB_Compiler_Unicode
#XmlEncoding = #PB_UTF8
CompilerElse
#XmlEncoding = #PB_Ascii
CompilerEndIf
#Dialog = 0
#Xml = 0
XML$ = "<window id='#PB_Any' name='test' text='test' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <panel>" +
" <tab text='First tab'>" +
" <vbox expand='item:2'>" +
" <hbox>" +
" <button text='button 1'/>" +
" <checkbox text='checkbox 1'/>" +
" <button text='button 2'/>" +
" </hbox>" +
" <editor text='content' height='150'/>" +
" </vbox>" +
" </tab>" +
" <tab text='Second tab'>" +
" </tab>" +
" </panel>" +
"</window>"
If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf