Fenster: Rahmen berechnen

  • Hey!

    Ich würde gerne die Rahmen eines Fensters berechnen.
    Ich gehe davon aus, dass die Ränder links, rechts und unten immer 4 Pixel breit, bzw. hoch sind.
    Das sollte meines Wissens nach noch korrekt sein ;)
    Nun möchte ich jedoch die Fensterleiste (oben), bzw. die Titelleiste im Fensterzustand berechnen.
    Ich bekomme es einfach nicht hin, wäre nett, wenn ihr mir dabei helfen könntet.

  • Moin,

    Spoiler anzeigen
    [autoit]

    ;
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    ; --- $WINDOWINFO
    Global Const $tagWINDOWINFO = _
    'dword cbSize;'& _
    'long rcWindow[4];'& _
    'long rcClient[4];'& _
    'dword dwStyle;'& _
    'dword dwExStyle;'& _
    'dword dwWindowStatus;'& _
    'uint cxWindowBorders;'& _
    'uint cyWindowBorders;'& _
    'ushort atomWindowType;'& _
    'ushort wCreatorVersion;'

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

    ; --- $TITLEBARINFO
    Global Const $tagTITLEBARINFO = _
    'dword cbSize;'& _
    'long rcTitleBar[4];'& _
    'dword rgstate[6];'

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

    Func GetTitleBarInfo ($hwnd, $pti)

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

    Local $aRes = DllCall ('user32.dll', 'int', 'GetTitleBarInfo', _
    'hwnd', $hwnd, _ ; handle to window
    'ptr', $pti) ; pointer to a TITLEBARINFO structure
    If @error Then _
    Return @error

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

    Return $aRes[0]

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

    EndFunc

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

    Func GetWindowInfo ($hwnd, $pwi)

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

    Local $aRes = DllCall ('user32.dll', 'int', 'GetWindowInfo', _
    'hwnd', $hwnd, _ ; handle to window
    'ptr', $pwi) ; pointer to a WINDOWINFO structure
    If @error Then _
    Return @error

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

    Return $aRes[0]

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

    EndFunc

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

    Func GetWindowFrameInfo ($hwnd)

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

    Local $sWinInfo
    Local $ti = DllStructCreate ($tagTITLEBARINFO)
    Local $wi = DllStructCreate ($tagWINDOWINFO)

    DllStructSetData ($wi, "cbSize", DllStructGetSize ($wi))
    DllStructSetData ($ti, "cbSize", DllStructGetSize ($ti))

    GetTitleBarInfo ($hwnd, DllStructGetPtr ($ti))

    GetWindowInfo ($hwnd, DllStructGetPtr ($wi))

    ConsoleWrite (StringFormat ("%17s %8s %8s\n", _
    "", _
    "Breite", _
    "Höhe"))

    ConsoleWrite (StringFormat ("%17s%10s%10s\n", "", "--------", "--------"))

    $sWinInfo = StringFormat ("%-17s %8d %8d\n", _
    "Titelleiste", _
    DllStructGetData ($ti, "rcTitleBar", 3) - DllStructGetData ($ti, "rcTitleBar", 1), _
    DllStructGetData ($ti, "rcTitleBar", 4) - DllStructGetData ($ti, "rcTitleBar", 2) _
    )

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

    ConsoleWrite ($sWinInfo)

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

    $sWinInfo = StringFormat ("%-17s %8d %8d\n", _
    "Fenster", _
    DllStructGetData ($wi, "rcWindow", 3) - DllStructGetData ($wi, "rcWindow", 1), _
    DllStructGetData ($wi, "rcWindow", 4) - DllStructGetData ($wi, "rcWindow", 2) _
    )

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

    ConsoleWrite ($sWinInfo)

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

    $sWinInfo = StringFormat ("%-17s %8d %8d\n", _
    "Anwendungsbereich", _
    DllStructGetData ($wi, "rcClient", 3) - DllStructGetData ($wi, "rcClient", 1), _
    DllStructGetData ($wi, "rcClient", 4) - DllStructGetData ($wi, "rcClient", 2) _
    )

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

    ConsoleWrite ($sWinInfo)

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

    $sWinInfo = StringFormat ("%-17s %8d %8d\n", _
    "Fensterränder", _
    DllStructGetData ($wi, "cxWindowBorders"), _
    DllStructGetData ($wi, "cyWindowBorders") _
    )

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

    ConsoleWrite ($sWinInfo)

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

    EndFunc

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

    $iWidth = 300
    $iHeight = 200

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

    $hWndMain = GUICreate ("Testfenster", _
    $iWidth, $iHeight, -1, -1, _
    BitOR ($WS_BORDER, $WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN), _
    $WS_EX_CLIENTEDGE)

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

    $idStatic_1 = GUICtrlCreateLabel ("", $iWidth+20, 20, $iWidth-20, $iHeight-60)
    $idButton_1 = GUICtrlCreateButton ("Fenster-Info", ($iWidth/2)-40, $iHeight-40, 80)

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

    GUISetState (@SW_SHOW, $hWndMain)

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

    While True

    Switch GUIGetMsg ( )
    Case -3
    ExitLoop
    Case $idButton_1
    GetWindowFrameInfo ($hWndMain)
    EndSwitch
    WEnd

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

    Exit (0)
    ;

    [/autoit]

    Gruß
    Greenhorn


    • Offizieller Beitrag

    Dafür gibt es in AutoIt _WinApi_GetSystemMetrics(Index).
    Ich hatte dafür dann eine Funktion erstellt, die wahlweise alle möglichen Parameter in eine MsgBox oder Commandline ausgibt ohne die Funktion auszuführen, bzw. ein Array mit allen Parametern zurückgibt. _GetSystemMetrics (kpl. in einem Aufruf)

  • Hey BugFix!
    Deine Methode schaut doch schon echt gut aus.
    Jedoch gibt es dabei in kleines Problem.
    Meine Titelleiste ist 22px hoch. Deine Funktion gibt jedoch 23px aus.
    Errechnen tue ich dies mit

    [autoit]

    $a = _GetSystemMetrics()
    MsgBox(0, "", $a[29] - $a[6])

    [/autoit]


    Bei den Themes von Windows funktioniert es jedoch.
    Eine Idee?

    Einmal editiert, zuletzt von Korby (26. Mai 2009 um 18:08)

  • und was ist damit?

    [autoit]

    $a = _GetSystemMetrics()
    MsgBox(0, "", $a[5]) ; ["SM_CYCAPTION",4,"Höhe von Überschrift/Titel"]

    [/autoit]


    und die schmale Titelleiste sollte das sein:

    [autoit]

    Const $SM_CYSMCAPTION = 51
    $data = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_CYSMCAPTION)
    MsgBox(0, '', $data[0])

    [/autoit]

    Einmal editiert, zuletzt von progandy (26. Mai 2009 um 21:58)

  • Ich spiele nun schon eine halbe Ewigkeit mit den Funktionen von Euch herum, jedoch geben diese einfach nicht die korrekten Werte aus.
    Hat denn niemand eine Idee?

  • Nun, die Werte stimmen schon, Du musst sie natürlich noch addieren. ;

    Die Titelleiste hat eine Höhe von 26 (XP), dazu musst Du natürlich noch die Breite des Rahmens hinzu addieren ...

    Das was bei der ganzen Geschichte nicht berechnet werden kann ist der Rahmen um den Anwendungsbereich, wenn das Fenster z.B. den Stil WS_EX_CLIENTEDGE besitzt.

    Spoiler anzeigen
    [autoit]

    ;
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    ; --- $WINDOWINFO
    Global Const $tagWINDOWINFO = _
    'dword cbSize;'& _
    'long rcWindow[4];'& _
    'long rcClient[4];'& _
    'dword dwStyle;'& _
    'dword dwExStyle;'& _
    'dword dwWindowStatus;'& _
    'uint cxWindowBorders;'& _
    'uint cyWindowBorders;'& _
    'ushort atomWindowType;'& _
    'ushort wCreatorVersion;'

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

    ; --- $TITLEBARINFO
    Global Const $tagTITLEBARINFO = _
    'dword cbSize;'& _
    'long rcTitleBar[4];'& _
    'dword rgstate[6];'

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

    Func GetTitleBarInfo ($hwnd, $pti)

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

    Local $aRes = DllCall ('user32.dll', 'int', 'GetTitleBarInfo', _
    'hwnd', $hwnd, _ ; handle to window
    'ptr', $pti) ; pointer to a TITLEBARINFO structure
    If @error Then _
    Return @error

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

    Return $aRes[0]

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

    EndFunc

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

    Func GetWindowInfo ($hwnd, $pwi)

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

    Local $aRes = DllCall ('user32.dll', 'int', 'GetWindowInfo', _
    'hwnd', $hwnd, _ ; handle to window
    'ptr', $pwi) ; pointer to a WINDOWINFO structure
    If @error Then _
    Return @error

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

    Return $aRes[0]

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

    EndFunc

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

    Func GetWindowFrameInfo ($hwnd, $idStatic)

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

    Local $sWinInfo
    Local $ti = DllStructCreate ($tagTITLEBARINFO)
    Local $wi = DllStructCreate ($tagWINDOWINFO)

    DllStructSetData ($wi, "cbSize", DllStructGetSize ($wi))
    DllStructSetData ($ti, "cbSize", DllStructGetSize ($ti))

    GetTitleBarInfo ($hwnd, DllStructGetPtr ($ti))

    GetWindowInfo ($hwnd, DllStructGetPtr ($wi))

    $sWinInfo = StringFormat ("%17s %8s %8s\n", _
    "", "Breite", "Höhe")

    $sWinInfo &= StringFormat ("%17s %8s %8s\n", _
    "", "--------", "--------")

    $sWinInfo &= StringFormat ("%-17s %8d %8d\n", _
    "Titelleiste", _
    DllStructGetData ($ti, "rcTitleBar", 3) - DllStructGetData ($ti, "rcTitleBar", 1), _
    DllStructGetData ($ti, "rcTitleBar", 4) - DllStructGetData ($ti, "rcTitleBar", 2) _
    )

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

    $sWinInfo &= StringFormat ("%-17s %8d %8d\n", _
    "Fenster", _
    DllStructGetData ($wi, "rcWindow", 3) - DllStructGetData ($wi, "rcWindow", 1), _
    DllStructGetData ($wi, "rcWindow", 4) - DllStructGetData ($wi, "rcWindow", 2) _
    )

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

    $sWinInfo &= StringFormat ("%-17s %8d %8d\n", _
    "Anwendungsbereich", _
    DllStructGetData ($wi, "rcClient", 3) - DllStructGetData ($wi, "rcClient", 1), _
    DllStructGetData ($wi, "rcClient", 4) - DllStructGetData ($wi, "rcClient", 2) _
    )

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

    $sWinInfo &= StringFormat ("%-17s %8d %8d\n", _
    "Fensterränder", _
    DllStructGetData ($wi, "cxWindowBorders"), _
    DllStructGetData ($wi, "cyWindowBorders") _
    )

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

    ConsoleWrite ($sWinInfo)

    GUICtrlSetData ($idStatic, $sWinInfo)

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

    EndFunc

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

    $iWidth = 300
    $iHeight = 200

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

    $hWndMain = GUICreate ("Testfenster", _
    $iWidth, $iHeight, -1, -1, _
    $WS_OVERLAPPEDWINDOW, _
    $WS_EX_OVERLAPPEDWINDOW)

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

    $idStatic_1 = GUICtrlCreateLabel ("", 10, 10, $iWidth-20, $iHeight-60)
    $idButton_1 = GUICtrlCreateButton ("Fenster-Info", ($iWidth/2)-40, $iHeight-40, 80)

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

    GUICtrlSetFont ($idStatic_1, 10, 400, 0, "Lucida Console")

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

    GUISetState (@SW_SHOW, $hWndMain)

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

    While True

    Switch GUIGetMsg ( )
    Case -3
    ExitLoop
    Case $idButton_1
    GetWindowFrameInfo ($hWndMain, $idStatic_1)
    EndSwitch
    WEnd

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

    Exit (0)

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

    ;

    [/autoit]


    Gruß
    Greenhorn