Page 1 of 1

Font selector

Posted: Sat Aug 25, 2007 4:39 am
by rsts
I can create the 'standard' windows font selector, but can't seem to find how to create a selector for the font name type only, as pictured.

Is there an API or must I create my own combobox list?

Hints and/or MSDN reference?

Image

Thanks

Re: Font selector

Posted: Sat Aug 25, 2007 5:48 am
by Fluid Byte
rsts wrote:Is there an API or must I create my own combobox list?
Of course this ain't an API standard. This should get you started:

Code: Select all

OpenWindow(0,0,0,320,240,"EnumFonts",#WS_OVERLAPPEDWINDOW | 1)
CreateGadgetList(WindowID(0))
ComboBoxGadget(0,10,10,250,400,#CBS_SORT)

Global NewList	 FaceName.s()

Procedure EnumFontFamExProc(*lpelfe.ENUMLOGFONTEX,*lpntme.NEWTEXTMETRICEX,FontType,lParam)
	FaceName$ = PeekS(@*lpelfe\elfFullName)
		
	Select FontType
		Case #TRUETYPE_FONTTYPE 
		Type$ + " [TT]"
	EndSelect
	
	ForEach FaceName()
		If FaceName() = FaceName$ + Type$ : Goto SkipFont : EndIf
	Next
	
	AddElement(FaceName())	
	FaceName() = FaceName$ + Type$ : Type$ = ""
	SkipFont:

	ProcedureReturn #True
EndProcedure

lf.LOGFONT
lf\lfCharset = #DEFAULT_CHARSET

hdc = GetDC_(WindowID(0))
EnumFontFamiliesEx_(hdc,lf,@EnumFontFamExProc(),0,0)
ReleaseDC_(WindowID(0),hdc)

ForEach FaceName()
	SendMessage_(GadgetID(0),#CB_ADDSTRING,0,FaceName())
Next

SetGadgetState(0,0)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend

Re: Font selector

Posted: Sat Aug 25, 2007 7:13 am
by rsts
Fluid Byte wrote:Of course this ain't an API standard. This should get you started: [snip]
And a nice start it is :)

gratz