custom font dialog box
https://www.autoitscript.com/forum/topic/213805-custom-font-dialog-box
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
_Example()
Func _Example()
Local $hGUI = GUICreate("Test Font_Dialog 0.23", 400, 250)
Local $idTest = GUICtrlCreateButton("Choose Font", 20, 20, 130, 30)
Local $sRead = ""
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idTest
GUICtrlSetState($idTest, $GUI_DISABLE)
$sRead = "" ; Clear previous
;Local $aFont = _Font_Dlg("Segoe Script", 10, 0xFF0000, 600, 0, $hGUI)
Local $aFont = _Font_Dlg("/Parent:" & $hGUI & " /Name:""Segoe Script"" /Size:10 /DarkMode:0 /Color:" & 0xFF6A00)
If @error Then
$sRead = "@error=" & @error & @CRLF
Else
For $i = 1 To $aFont[0]
$sRead &= "[" & $i & "] = " & $aFont[$i] & @CRLF
Next
; Apply Font: Size, Weight, Attribute (Bitmask), Name
GUICtrlSetFont($idTest, $aFont[1], $aFont[2], $aFont[3], $aFont[4])
GUICtrlSetColor($idTest, $aFont[5])
EndIf
MsgBox($MB_TOPMOST, "Returned from Font_Dialog", $sRead, 0, $hGUI)
ConsoleWrite("Returned from Font_Dialog:" & @CRLF & $sRead & @CRLF)
GUICtrlSetState($idTest, $GUI_ENABLE)
EndSwitch
WEnd
GUIDelete($hGUI)
EndFunc ;==>_Example
; #FUNCTION# ====================================================================================================================
; Name ..........: _Font_Dlg
; Description ...: Calls the external Font_Dialog process to select font properties.
; Syntax ........: _Font_Dlg([$sOptions = ""])
; Parameters ....: $sOptions - [optional] CLI parameter string.
; Supported flags: /Name: /Size: /Color: /Weight: /Attribute: /Parent: /DarkMode:
; Return values .: Success - Returns 1D Array: [1]=Size, [2]=Weight, [3]=Attribute, [4]=FontName, [5]=Color
; Failure - Sets @error = 1 and returns ""
; Example .......: _Font_Dlg("/Parent:" & $hGUI & " /Name:Segoe UI /Size:12")
; ===============================================================================================================================
Func _Font_Dlg($sOptions = "")
Local $sFont_Dialog_Path = @ScriptDir & '\Font_Dialog.au3'
Local $sStr, $sParams = ""
Local $aArg = StringSplit($sOptions, "/")
If $aArg[0] > 1 Then
For $i = 2 To $aArg[0]
$sStr = StringStripWS($aArg[$i], 3)
If $sStr = "" Then ContinueLoop
; Encode Name parameter to Hex for safe CLI passing
If StringLeft($sStr, 5) = "Name:" Then
$sStr = StringTrimLeft($sStr, 5)
$sStr = StringRegExpReplace($sStr, "^['""]+|['""]+$", "") ; Strip quotes if any
$sStr = "Name:" & StringToBinary($sStr, 4)
EndIf
$sParams &= " /" & $sStr
Next
EndIf
; Build & execute command
Local $sCmd = '"' & @AutoItExe & '"' & (@Compiled ? ' ' : ' /AutoIt3ExecuteScript ')
$sCmd &= '"' & $sFont_Dialog_Path & '"' & $sParams
Local $iPID = Run($sCmd, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
If Not $iPID Then Return SetError(1, 0, "")
ProcessWaitClose($iPID)
Local $sOutput = StringStripWS(StdoutRead($iPID), 3)
If $sOutput <> "" Then Return StringSplit($sOutput, "|", 1)
Return SetError(1, 0, "")
EndFunc ;==>_Font_Dlg
;---------------------------------------------------------------------------------------


Comments
Post a Comment