Sign in to follow this  
Followers 0
Floppy

Fonts in combo-box

11 posts in this topic

#1 ·  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



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

Doesn't work.... :)

Share this post


Link to post
Share on other sites

#4 ·  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

#5 ·  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

#6 ·  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

@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

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

change this line:

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

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

thank you

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