Getting the systems default font
Getting the systems default font
I need to get the font name, size, style of the Window Style. So I can create the gadgets with the correct size
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
I honestly don't know how to get the font info from the handle, but you may find this of some use:
Code: Select all
; window to test with
OpenWindow(0,0,0,320,240,"")
; get its font
wfont = SendMessage_(WindowID(0),#WM_GETFONT,0,0)
If Not wfont
wfont = GetStockObject_(#DEFAULT_GUI_FONT)
EndIf
; find size for longest string you want to use
tmp = CreateImage(#PB_Any, 1024, 100)
StartDrawing(ImageOutput(tmp))
DrawingFont(wfont)
Debug TextWidth("this is the longest string I will want to write")
Debug TextHeight("This is how tall it will be")
StopDrawing()
FreeImage(tmp)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
Once you have the font handle, GetObject_() will fill in a LOGFONT structure for you from which the relevant font metrics and face name can be obtained.
However, for gadget positioning etc. it is not the font metrics you require but the text metrics and for that, netty's code above will do the job quite nicely for 'standard fonts'. For things like italic fonts you need to delve a wee bit deeper, but things get complex at that point!
However, for gadget positioning etc. it is not the font metrics you require but the text metrics and for that, netty's code above will do the job quite nicely for 'standard fonts'. For things like italic fonts you need to delve a wee bit deeper, but things get complex at that point!

I may look like a mule, but I'm not a complete ass.