Windows Standardschrift auslesen

  • Hi,
    ich würde gerne für Windows die Standardschrift und Standardgröße mit AutoIt auslesen, die für Labels verwendet wird.
    Hintergrund: Ich will die Länge von Labels automatisch vor dem erstellen in der GUI ermitteln. Dazu brauche ich diese Standardwerte.
    Für Windows 7 müsste es "Segoe UI" sein.

    Weiß einer wie dies geht :?:

  • Spoiler anzeigen
    [autoit]

    #cs
    typedef struct tagNONCLIENTMETRICS {
    UINT cbSize;
    int iBorderWidth;
    int iScrollWidth;
    int iScrollHeight;
    int iCaptionWidth;
    int iCaptionHeight;
    LOGFONT lfCaptionFont;
    int iSmCaptionWidth;
    int iSmCaptionHeight;
    LOGFONT lfSmCaptionFont;
    int iMenuWidth;
    int iMenuHeight;
    LOGFONT lfMenuFont;
    LOGFONT lfStatusFont;
    LOGFONT lfMessageFont;
    #if (WINVER >= 0x0600)
    int iPaddedBorderWidth;
    #endif
    } NONCLIENTMETRICS,
    *LPNONCLIENTMETRICS;

    [/autoit] [autoit][/autoit] [autoit]

    typedef struct tagLOGFONT {
    LONG lfHeight;
    LONG lfWidth;
    LONG lfEscapement;
    LONG lfOrientation;
    LONG lfWeight;
    BYTE lfItalic;
    BYTE lfUnderline;
    BYTE lfStrikeOut;
    BYTE lfCharSet;
    BYTE lfOutPrecision;
    BYTE lfClipPrecision;
    BYTE lfQuality;
    BYTE lfPitchAndFamily;
    TCHAR lfFaceName[LF_FACESIZE];
    } LOGFONT, *PLOGFONT;
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    $nonclientmetrics = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
    DllStructSetData($nonclientmetrics, 1, DllStructGetSize($nonclientmetrics))

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $SPI_GETNONCLIENTMETRICS = 41

    [/autoit] [autoit][/autoit] [autoit]

    $a = DllCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($nonclientmetrics), "ptr", DllStructGetPtr($nonclientmetrics), "int", 0)
    $b = DllCall("kernel32.dll", "int", "GetLastError")

    [/autoit] [autoit][/autoit] [autoit]

    ;~ MsgBox(4096, "SystemParametersInfo", "Last error: " & $b[0] & @CRLF& "SystemParametersInfo return value: " & $a[0])

    [/autoit] [autoit][/autoit] [autoit]

    $logfont1 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DllStructGetPtr($nonclientmetrics, 7))
    $logfont2 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DllStructGetPtr($nonclientmetrics, 10))
    $logfont3 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DllStructGetPtr($nonclientmetrics, 13))
    $logfont4 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DllStructGetPtr($nonclientmetrics, 14))
    $logfont5 = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DllStructGetPtr($nonclientmetrics, 15))

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(4096, "Fonts", "CaptionFont: " & DllStructGetData($logfont1, 14) & " - " & - DllStructGetData($logfont1, 1) & " - " & DllStructGetData($logfont1, 5) & @LF & _
    "SmCaptionWidth: " & DllStructGetData($logfont2, 14) & " - " & - DllStructGetData($logfont2, 1) & " - " & DllStructGetData($logfont2, 5) & @LF & _
    "MenuFont: " & DllStructGetData($logfont3, 14) & " - " & - DllStructGetData($logfont3, 1) & " - " & DllStructGetData($logfont3, 5) & @LF & _
    "StatusFont: " & DllStructGetData($logfont4, 14) & " - " & - DllStructGetData($logfont4, 1) & " - " & DllStructGetData($logfont4, 5) & @LF & _
    "MessageFont: " & DllStructGetData($logfont5, 14) & " - " & - DllStructGetData($logfont5, 1) & " - " & DllStructGetData($logfont5, 5))

    [/autoit]
  • Friesel
    den Regkey habe ich inzwischen auch gefunden. Jedoch kann ich die Daten nicht in brauchbare Infos umwandeln.
    zum setzen der Länge würde ich TextMeter von BugFix verwenden. Denke damit sollte es auch funktionieren.

    funkey
    als Höhe wird 12 ausgegeben. Dies kann aber nicht sein.
    Es müsste 8 oder 8.5 sein :huh:

  • Hab das Skript mal umgeschrieben, damit es übersichtlicher wird und die Font-Höhe passend ausgegeben wird.
    BTW: Die Funktion SystemParametersInfo() muss ich in Zukunft öfter verwenden, damit kann man sehr viel anstellen!

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $tagNONCLIENTMETRICS = "UINT cbSize;int iBorderWidth;int iScrollWidth;int iScrollHeight;int iCaptionWidth;" & _
    "int iCaptionHeight;byte lfCaptionFont[92];int iSmCaptionWidth;int iSmCaptionHeight;byte lfSmCaptionFont[92];int iMenuWidth;" & _
    "int iMenuHeight;byte lfMenuFont[92];byte lfStatusFont[92];byte lfMessageFont[92];int iPaddedBorderWidth"

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $SPI_GETNONCLIENTMETRICS = 0x0029

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $tCaptionFont, $tSmCaptionFont, $tMenuFont, $tStatusFont, $tMessageFont
    Global $tNonClientMetrics = DllStructCreate($tagNONCLIENTMETRICS)
    Global $iDllStructSize = DllStructGetSize($tNonClientMetrics)
    If @OSVersion < 0x0600 Then $iDllStructSize -= 4

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($tNonClientMetrics, "cbSize", $iDllStructSize)

    [/autoit] [autoit][/autoit] [autoit]

    If _WinAPI_SystemParametersInfo($SPI_GETNONCLIENTMETRICS, $iDllStructSize, DllStructGetPtr($tNonClientMetrics)) Then
    $tCaptionFont = DllStructCreate($tagLOGFONT, DllStructGetPtr($tNonClientMetrics, "lfCaptionFont"))
    $tSmCaptionFont = DllStructCreate($tagLOGFONT, DllStructGetPtr($tNonClientMetrics, "lfSmCaptionFont"))
    $tMenuFont = DllStructCreate($tagLOGFONT, DllStructGetPtr($tNonClientMetrics, "lfMenuFont"))
    $tStatusFont = DllStructCreate($tagLOGFONT, DllStructGetPtr($tNonClientMetrics, "lfStatusFont"))
    $tMessageFont = DllStructCreate($tagLOGFONT, DllStructGetPtr($tNonClientMetrics, "lfMessageFont"))

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("CaptionFont:"& @TAB & _GetFontInfo($tCaptionFont, 1) & " / " & _GetFontInfo($tCaptionFont, 2) & " / " & _GetFontInfo($tCaptionFont, 3) & @LF)
    ConsoleWrite("SmCaptionFont:"& @TAB & _GetFontInfo($tSmCaptionFont, 1) & " / " & _GetFontInfo($tSmCaptionFont, 2) & " / " & _GetFontInfo($tSmCaptionFont, 3) & @LF)
    ConsoleWrite("MenuFont:"& @TAB & _GetFontInfo($tMenuFont, 1) & " / " & _GetFontInfo($tMenuFont, 2) & " / " & _GetFontInfo($tMenuFont, 3) & @LF)
    ConsoleWrite("StatusFont:"& @TAB & _GetFontInfo($tStatusFont, 1) & " / " & _GetFontInfo($tStatusFont, 2) & " / " & _GetFontInfo($tStatusFont, 3) & @LF)
    ConsoleWrite("MessageFont:"& @TAB & _GetFontInfo($tMessageFont, 1) & " / " & _GetFontInfo($tMessageFont, 2) & " / " & _GetFontInfo($tMessageFont, 3) & @LF)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetFontInfo($tLogFont, $iRet = 0)
    If $iRet < 0 Or $iRet > 3 Then Return SetError(1, 0, 0)
    Local Const $LOGPIXELSY = 90
    Local $aFontInfo[3]
    $aFontInfo[0] = DllStructGetData($tLogFont, "FaceName")
    $aFontInfo[1] = Round(-DllStructGetData($tLogFont, "Height") * 72 / _WinAPI_GetDeviceCaps(_WinAPI_GetDC(0), $LOGPIXELSY), 1)
    $aFontInfo[2] = DllStructGetData($tLogFont, "Weight")
    If $iRet = 0 Then
    Return $aFontInfo
    Else
    Return $aFontInfo[$iRet - 1]
    EndIf
    EndFunc ;==>_GetFontInfo

    [/autoit]