Sign in to follow this  
Followers 0

Fonts in combo-box

11 posts in this topic

Posted (edited)

Hello, sorry for my english...

How can I list all fonts installate on the system in a combo-box?

I'm tried to read the subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts with the script:

$reg_index=0
Do
$reg_index=$reg_index+1
$reg_read=RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",$reg_index)
GUICtrlSetData($font,$reg_read&"|")
Until @error<>0

But, I get an error message ("Available data no longer available", or something like this) in the combo-box, instead of the fonts.

Can anyone help me, please? Thanks in advance...

Edited by FSoft

Share this post


Link to post
Share on other sites



Posted

Maybe

$reg_read_all = ""
$reg_index=0
Do
	$reg_index=$reg_index+1
	$reg_read=RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",$reg_index)
	$reg_read_all &= $reg_read & "|"
Until @error<>0

GUICtrlSetData($font,$reg_read_all)

Share this post


Link to post
Share on other sites

Posted

Doesn't work.... :)

Share this post


Link to post
Share on other sites

Posted (edited)

Use RegEnumVal instead of RegEnumKey :)

GUICreate("sdsd")
	$font = GUICtrlCreateCombo("",10,10,150,23)
GUISetState()



$reg_read_all = ""
$reg_index=0

Do
	$reg_index += 1
	$reg_read = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",$reg_index)
	$iError = @error
	
	If Not $iError Then $reg_read_all &= $reg_read & "|"
	
Until $iError<>0



GUICtrlSetData($font,$reg_read_all)



While 1
	
WEnd
Edited by Kip

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks, the script works...but the fonts are showed with the suffix (True Type): for example "Arial Black (True Type)". For fix this I have add the command:

$reg_read=StringReplace($reg_read,"(True Type)","")

..but doesn't work...

Another question: How can I show a preview of the fonts in the combo?

Edited by FSoft

Share this post


Link to post
Share on other sites

Posted (edited)

GUICreate("sdsd")
	$font = GUICtrlCreateCombo("",10,10,150,23)
GUISetState()



$reg_read_all = ""
$reg_index=0

Do
	$reg_index += 1
	$reg_read = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",$reg_index)
	$iError = @error
	
	If Not $iError Then
		
		$iPos = StringInStr($reg_read," (")
		$sFontName = $reg_read
		If $iPos Then $sFontName = StringLeft($reg_read,$iPos-1)
		
		$reg_read_all &= $sFontName & "|"
	EndIf
	
Until $iError<>0



GUICtrlSetData($font,$reg_read_all)



While 1
	
WEnd

Another question: How can I show a preview of the fonts in the combo?

You can't do that with a regular combobox. Edited by Kip

Share this post


Link to post
Share on other sites

Posted

@FSoft

Example:

#include <GuiConstantsEx.au3>

Dim $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"

GUICreate("Test", 400, 100)

$cCombo_Font = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($cCombo_Font, _RegEnumVal($sRegKey))

$cLabel = GUICtrlCreateLabel("Font preview", 230, 10, 155, 20)

GUISetState()

While 1
	$msg = GUIGetMsg()
	Switch $msg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $cCombo_Font
			GUICtrlSetFont($cLabel, 10, Default, Default, GUICtrlRead($cCombo_Font))
	EndSwitch
WEnd

Func _RegEnumVal($sKey)
	Local $i = 1, $sVal, $sResult
	
	While 1
		$sVal = RegEnumVal($sKey, $i)
		If @error Then ExitLoop
		$i += 1
		$sResult &= $sVal & "|"
	WEnd
	
	Return StringRegExpReplace($sResult, " \(.*?\)", "")
EndFunc   ;==>_RegEnumVal

Share this post


Link to post
Share on other sites

Posted

Thanks, it works...but now there's another problem: The fonts aren't sorted alphabetically (is this a correct english term? :)).

How can I sort it?

thank you!

Share this post


Link to post
Share on other sites

Posted

change this line:

$cCombo_Font = GUICtrlCreateCombo("", 10, 10, 200, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL)

Jos

Share this post


Link to post
Share on other sites

Posted

thank you

Share this post


Link to post
Share on other sites

Posted

Tnx for this. Exactly what I wanted. :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0