Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Fonts in combo-box


  • Please log in to reply
10 replies to this topic

#1 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 24 December 2008 - 04:31 PM

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, 24 December 2008 - 04:32 PM.








#2 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 24 December 2008 - 04:58 PM

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)


#3 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 24 December 2008 - 05:03 PM

Doesn't work.... :)

#4 Kip

Kip

    Into the JavaScript

  • Active Members
  • PipPipPipPipPipPip
  • 1,690 posts

Posted 24 December 2008 - 07:07 PM

Use RegEnumVal instead of RegEnumKey :)
Plain Text         
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, 24 December 2008 - 07:17 PM.


#5 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 25 December 2008 - 09:00 AM

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, 25 December 2008 - 09:36 AM.


#6 Kip

Kip

    Into the JavaScript

  • Active Members
  • PipPipPipPipPipPip
  • 1,690 posts

Posted 25 December 2008 - 11:21 AM

Plain Text         
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, 25 December 2008 - 11:24 AM.


#7 rasim

rasim

    Gray Scripter

  • Active Members
  • PipPipPipPipPipPip
  • 1,708 posts

Posted 25 December 2008 - 11:38 AM

@FSoft
Example:
AutoIt         
#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

OS: Windows XP SP3, AutoIt version: 3.3.0.0Posted Image My Projects: Free_Resources | Splitter | wgetGUI | UnRARIt | USBMon | CDROM-Control | Volume Serial Changer | WinTrayPosted Image My UDFs: _ScreenSetting | ListView_Progress | ContextHelp | ToolTip_UDF | UnRAR | Zip32 | BassMod | ShellTreeView | GuiHotKey | 7ZipPosted Image My Examples: TrayIcon_Click | SystemTray_Refresh | _ListView_Sort | CPUmonLike above scripts? Please rate the topic Posted Image

#8 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 25 December 2008 - 01:30 PM

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!

#9 Jos

Jos

    oh joy ...

  • Developers
  • 22,534 posts

Posted 25 December 2008 - 01:57 PM

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                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#10 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 25 December 2008 - 03:51 PM

thank you

#11 leomoon

leomoon

    Adventurer

  • Active Members
  • PipPip
  • 126 posts

Posted 19 July 2012 - 11:24 PM

Tnx for this. Exactly what I wanted. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users