Getting the systems default font

Just starting out? Need help? Post your questions and find answers here.
funnyguy
User
User
Posts: 69
Joined: Mon Jun 23, 2008 10:57 pm

Getting the systems default font

Post by funnyguy »

I need to get the font name, size, style of the Window Style. So I can create the gadgets with the correct size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Are you talking about sizing a gadget to fit the text to be placed inside it?

I don't want to attempt to answer your question when I'm not very clear what it is you're after.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

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! :)
I may look like a mule, but I'm not a complete ass.
Post Reply