- Offizieller Beitrag
Folgendes Problem:
GuiSetFont und GuiCtrlSetFont verwenden als Default-Parameter:
- Size 8.5
- Fontname OS-GUI-Font
Ich wollte eine Möglichkeit haben, nach Veränderungen am Font diesen auf "Default" zurückzusetzen.
Hier ein Skriptbsp., das zeigt - es ist absolut unmöglich. Weder Größe noch Aussehen des Font sind tatsächlich mit dem Original nach Ersterstellung identisch.
"Label-1" bleibt zum Vergleich unverändert.
Spoiler anzeigen
#include <GuiConstants.au3>
#include <GuiSlider.au3>
$hGui = GUICreate('Test')
$Label_1 = GUICtrlCreateLabel('Label-1', 20, 20, 80)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label_2 = GUICtrlCreateLabel('Label-2', 20, 45, 80)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$sFontName = _SysGetFont()[3]
GUICtrlCreateLabel('System Font: ' & $sFontName, 20, 70, 180, 20)
GUICtrlCreateLabel('Setze Font für Label-2: System, Size vom Slider', 20, 100)
$slider = GUICtrlCreateSlider(20, 120, 200, 20, $TBS_AUTOTICKS)
GUICtrlSetLimit(-1, 28, 12)
_GUICtrlSlider_SetPos($slider, 17)
$lblSize = GUICtrlCreateLabel(GUICtrlRead($slider)/2, 230, 123, 30)
$btSetFont = GUICtrlCreateButton('Setze Font', 20, 160, 60, 22)
GUISetState()
[/autoit] [autoit][/autoit] [autoit]While True
Switch GUIGetMsg()
Case -3
Exit
Case $btSetFont
GUICtrlSetFont($Label_2, GUICtrlRead($slider)/2, 400, 0, $sFontName)
Case $slider
GUICtrlSetData($lblSize, GUICtrlRead($slider)/2)
EndSwitch
WEnd
;===============================================================================
; Function Name....: _SysGetFont()
; Description......: Gets from Source the system settings for the font parameters
; Parameter(s).....: $iFontSource 0='Titlebar' (default), 1='Palette', 2='Menu', 3='ToolTip', 4='MessageBox'
; Return Value(s)..: [size, weight, attributes, fontname, quality]
; Author(s)........: BugFix ( [email='bugfix@autoit.de'][/email] )
;===============================================================================
Func _SysGetFont($iFontSource=0)
Local $tNONCLIENTMETRICS = DllStructCreate('struct; uint cbSize;int iBorderWidth;int iScrollWidth;' & _
'int iScrollHeight;int iCaptionWidth;int iCaptionHeight;byte lfCaptionFont[60];int iSMCaptionWidth;' & _
'int iSMCaptionHeight;byte lfSMCaptionFont[60];int iMenuWidth;int iMenuHeight;byte lfMenuFont[60];' & _
'byte lfStatusFont[60];byte lfMessageFont[60];int iPaddedBorderWidth;endstruct')
DllStructSetData($tNONCLIENTMETRICS, 'cbSize', DllStructGetSize($tNONCLIENTMETRICS))
DllCall('user32', 'int', 'SystemParametersInfoA', 'int', 41, 'int', DllStructGetSize($tNONCLIENTMETRICS), _
'ptr', DllStructGetPtr($tNONCLIENTMETRICS), 'int', 0)
Local $tagLF = 'struct;long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32];endstruct'
Local $aFontSource[5] = ['lfCaptionFont','lfSMCaptionFont','lfMenuFont','lfStatusFont','lfMessageFont']
Local $tLogFont = DllStructCreate($tagLF, DllStructGetPtr($tNONCLIENTMETRICS, $aFontSource[$iFontSource]))
Local $aOut[5] = [ _
Abs(DllStructGetData($tLogFont, 1))*0.7, _ ; Height * size
DllStructGetData($tLogFont, 5), _ ; Weight * weight
DllStructGetData($tLogFont, 6) + _ ; Italic * attribute
DllStructGetData($tLogFont, 7) + _ ; Underline * attribute
DllStructGetData($tLogFont, 8), _ ; StrikeOut * attribute
DllStructGetData($tLogFont, 14), _ ; FaceName * fontname
DllStructGetData($tLogFont, 12)] ; Quality * quality
Return $aOut
EndFunc ;==>_SysGetFont
Hat jemand eine Idee, welche Werte tatsächlich dort verwendet werden? Nach meinem Verständnis liegt das Problem in AutoIt selbst begraben. In der Art, wie die Parameter vom Betriebssystem übernommen und umgesetzt werden. Beim Abfragen der Werte vom OS erhält man die Angaben aus dem LOGFONT als logische Größe (12). Mit dem Faktor 0.7 kann man dann näherungsweise den in AutoIt verwendeten Wert von 8.5 erreichen (rechnerisch 8.4).
Die Lösung mit der Brechstange wäre natürlich, das Ctrl zu löschen und neu zu erstellen. Dann habe ich den sauberen Ausgangszustand, allerdings habe ich auch eine neue ID und muss ggf. für alle Funktionen, die das Ctrl nutzen noch ein ID-Management vorhalten.