Jump to content

Fonts in combo-box


Floppy
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
Link to comment
Share on other sites

  • Developers

change this line:

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 3 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...