HalliHallo
diese Frage bezieht sich genau auf das Problem, welches ich gerade versuche im Englischen Forum zu lösen. Die hervorragende Extended Message Box UDF von Melba23 funktioniert tadellos unter Vista und Win7. Unter XP bekomme ich es aber nicht hin, den Default Font auszulesen. Woran liegt das? Ich denke genau an der Art und Weise wie ProgAndy oben in seiner Funktion die $PointSize berechnet. Die Funktion _WinAPI_MulDiv() gibt nur ganze Zahlen zurück, Fonts erlauben aber auch eine dezimale Größenangabe, und unter XP ist der Default Font (auf meinem Rechner) Tahoma/8.5...
Spoiler anzeigen
#include-once
#include<WindowsConstants.au3>
#include<WinAPI.au3>
; http://www.autoit.de/index.php?page…4016#post134016
; ProgAndy
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlGetFont
; Description ...: gets the font of a GUI Control
; Syntax.........: _GUICtrlGetFont( [$hWnd] )
; Parameters ....: $hWnd - [optional] ControlID or Handle of the control. Default is last created GUICtrl... (-1)
; Return values .: Success - Array with options of font:
; [0] - Fontsize
; [1] - Font weight (400 = normal).
; [2] - italic:2 underlined:4 strike:8 char format (styles added together, 2+4 = italic and underlined).
; [3] - The name of the font to use.
; [4] - Font quality to select (PROOF_QUALITY=2 is default in AutoIt).
; Failure - 0, @error set to nonzero
; Author ........: Prog@ndy
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _GUICtrlGetFont($hWnd = -1)
; Author: Prog@ndy
Local $hFONT
Switch IsHWnd($hWnd)
Case True
$hFONT = _SendMessage($hWnd, $WM_GETFONT)
Case Else
$hFONT = GUICtrlSendMsg($hWnd, $WM_GETFONT, 0, 0)
$hWnd = GUICtrlGetHandle($hWnd)
EndSwitch
If Not $hFONT Then Return SetError(1, 0, 0)
Local $tFONT = DllStructCreate($tagLOGFONT)
Local $aReturn = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFONT, 'int', DllStructGetSize($tFONT), 'ptr', DllStructGetPtr($tFONT))
If @error Or $aReturn[0] = 0 Then Return SetError(2, 0, 0)
Local $hDC = _WinAPI_GetDC($hWnd)
ConsoleWrite(DllStructGetData($tFONT, 'Height') & @crlf)
Local $PointSize = -1 * _WinAPI_MulDiv(DllStructGetData($tFONT, 'Height'), 72, _WinAPI_GetDeviceCaps($hDC, 90)) ; $LOGPIXELSY
_WinAPI_ReleaseDC($hWnd, $hDC)
Local $aReturn[5] = [$PointSize, DllStructGetData($tFONT, 'Weight'), _
2 * (True = DllStructGetData($tFONT, 'Italic')) + 4 * (True = DllStructGetData($tFONT, 'Underline')) + 8 * (True = DllStructGetData($tFONT, 'StrikeOut')), _
DllStructGetData($tFONT, 'FaceName'), DllStructGetData($tFONT, 'Quality')]
Return $aReturn
EndFunc ;==>_GUICtrlGetFont
;-----------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]#include<Array.au3>
GUICreate("bla")
GUICtrlCreateLabel("test", 10, 10, 100, 100)
[/autoit] [autoit][/autoit] [autoit]$label = GUICtrlCreateLabel("test", 10, 50, 100, 100)
GUICtrlSetFont($label,
GUISetState()
[/autoit] [autoit][/autoit] [autoit]$font = _GUICtrlGetFont($label)
_ArrayDisplay($font)
GUICtrlSetFont($label, 8.5)
$font = _GUICtrlGetFont($label)
_ArrayDisplay($font)
GUICtrlSetFont($label, 10.5)
$font = _GUICtrlGetFont($label)
_ArrayDisplay($font)
GUICtrlSetFont($label, 11)
$font = _GUICtrlGetFont($label)
_ArrayDisplay($font)
GUICtrlSetFont($label, 11.5)
$font = _GUICtrlGetFont($label)
_ArrayDisplay($font)
ConsoleWrite(_WinAPI_MulDiv(Abs(-10), 72, 96) & @crlf)
ConsoleWrite(_WinAPI_MulDiv(Abs(-11), 72, 96) & @crlf)
Ich hab mich schon durch MSDN gewühlt und bin dann bei einer ähnlichen Lösung wie oben dargestellt stecken geblieben.
http://msdn.microsoft.com/en-us/library/ms901140.aspx
Ich befürchte die Antwort liegt in diesem Satz versteckt: "The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts."
GUICtrlSetFont($label, 8, 400, 0, "Tahoma") sieht eindeutig anders aus wie
GUICtrlSetFont($label, 8.5, 400, 0, "Tahoma")
Der Rückgabewert von LOGFONT für den ersten Fall ist -10, für den zweiten Fall -11... wobei gilt:
_WinAPI_MulDiv(Abs(-10), 72, 96) = 8
_WinAPI_MulDiv(Abs(-11), 72, 96) = 8
Hat vielleicht jemand eine schlaue Idee dazu :wacko: ?
Gruß