control size ermitteln in pixel

  • Ich bin ein wenig verzweifelt, bräuchte mal eure Hilfe. Gibt es ein UDF zum Ermitteln von Control Size (Pic, Button, ect...) in Pixel? Kein DPI! Vielen Dank für eure antworten

    Einmal editiert, zuletzt von getdot (2. August 2011 um 15:35)

  • Braucht man keine UDF dazu, die Funktion controlgetpos() reicht völlig:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <array.au3>

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

    $Form1 = GUICreate("Form1", 625, 445, 192, 124)
    $Button1 = GUICtrlCreateButton("Button1", 88, 80, 75, 25, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("Button2", 112, 200, 97, 209, $WS_GROUP)
    $Edit1 = GUICtrlCreateEdit("", 272, 96, 225, 121)
    GUICtrlSetData(-1, "Edit1")
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1,$Button2
    $test1 = ControlGetPos ( "", "", $Button1 )
    $test2 = ControlGetPos ( "", "", $Button2 )
    $test3 = ControlGetPos ( "", "", $Edit1 )
    _ArrayDisplay($test1,"Infos Button 1")
    _ArrayDisplay($test2,"Infos Button 2")
    _ArrayDisplay($test3,"Infos Edit 1")
    EndSwitch
    WEnd

    [/autoit]
  • Erst einmal Danke für eure Antworten! :)

    Das stimmt nicht! Hier ein Script zum Testen

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>
    #include <GDIPlus.au3>

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

    Local $guiX = 600, $guiY = 400, $VarPic = @SystemDir & "\oobe\images\mslogo.jpg", $updatepic = 0
    $gui = GUICreate("test", 610, 430, -1, -1)
    $pic = GUICtrlCreatePic($VarPic, 10, 40, 200, 150)

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

    $Buton = GUICtrlCreateButton("Bild Laden", 10, 10, 80, 25)

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

    GUICtrlCreateGroup("Dots per inch", 95, 0, 250, 35)
    $Xcor = GUICtrlCreateLabel("X = 10", 100, 15, 60, 15)
    GUICtrlSetFont(-1, 10)

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

    $Ycor = GUICtrlCreateLabel("Y = 40", 160, 15, 60, 15)
    GUICtrlSetFont(-1, 10)

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

    $Wcor = GUICtrlCreateLabel("W = 200", 220, 15, 60, 15)
    GUICtrlSetFont(-1, 10)

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

    $Hcor = GUICtrlCreateLabel("H = 150", 280, 15, 60, 15)
    GUICtrlSetFont(-1, 10)

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

    $Butonsave = GUICtrlCreateButton("Bild Speichern", 360, 10, 80, 25)

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()
    $aMP = GUIGetCursorInfo($gui)
    If IsArray($aMP) Then
    If $aMP[4] = $pic Then
    $aMPos = MouseGetPos()
    $aCPos = ControlGetPos($gui, "", $pic)
    Do
    $aMPosNew = MouseGetPos()
    If _IsPressed("01") Then
    GUICtrlSetCursor($pic, 9)

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

    If $aCPos[0] + $aMPosNew[0] - $aMPos[0] - 10 < 0 And $aCPos[1] + $aMPosNew[1] - $aMPos[1] - 40 < 0 Then
    ControlMove($gui, "", $pic, 10, 40)
    $updatepic = 1
    ExitLoop

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

    ElseIf $aCPos[0] + $aMPosNew[0] - $aMPos[0] - 10 < 0 Then
    ControlMove($gui, "", $pic, 10, $aCPos[1] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    ExitLoop

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

    ElseIf $aCPos[1] + $aMPosNew[1] - $aMPos[1] - 40 < 0 Then
    ControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], 40)
    $updatepic = 1
    ExitLoop

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

    ElseIf $aCPos[0] + $aMPosNew[0] - $aMPos[0] + $aCPos[2] > $guiX Then
    ControlMove($gui, "", $pic, $guiX - $aCPos[2], $aCPos[1] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    ExitLoop

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

    ElseIf $aCPos[1] + $aMPosNew[1] - $aMPos[1] + $aCPos[3] > $guiY Then
    ControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], $guiY - $aCPos[3])
    $updatepic = 1
    ExitLoop
    EndIf

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

    ControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], $aCPos[1] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    EndIf
    Until Not _IsPressed("01")

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

    Do
    $aMPosNew = MouseGetPos()
    If _IsPressed("02") Then
    GUICtrlSetCursor($pic, 12)
    If $aCPos[3] + $aMPosNew[1] - $aMPos[1] < 5 And $aCPos[2] + $aMPosNew[0] - $aMPos[0] < 5 Then
    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], 5, 5)
    $updatepic = 1
    $aCPosinput = ControlGetPos($gui, "", $pic)
    ExitLoop

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

    ElseIf $aCPos[2] + $aMPosNew[0] - $aMPos[0] < 5 Then
    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], 5, $aCPos[3] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    $aCPosinput = ControlGetPos($gui, "", $pic)
    ExitLoop

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

    ElseIf $aCPos[3] + $aMPosNew[1] - $aMPos[1] < 5 Then
    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], 5)
    $updatepic = 1
    $aCPosinput = ControlGetPos($gui, "", $pic)
    ExitLoop

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

    ElseIf $aCPos[0] + $aCPos[2] + $aMPosNew[0] - $aMPos[0] > $guiX Then
    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $guiX - $aCPos[0], $aCPos[3] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    $aCPosinput = ControlGetPos($gui, "", $pic)
    ExitLoop

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

    ElseIf $aCPos[1] + $aCPos[3] + $aMPosNew[1] - $aMPos[1] > $guiY Then
    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], $guiY - $aCPos[1])
    $updatepic = 1
    $aCPosinput = ControlGetPos($gui, "", $pic)
    ExitLoop
    EndIf

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

    ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], $aCPos[3] + $aMPosNew[1] - $aMPos[1])
    $updatepic = 1
    EndIf
    Until Not _IsPressed("02")

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

    If $updatepic = 1 Then
    GUICtrlSetImage($pic, $VarPic)
    GUICtrlSetCursor($pic, 2)
    $updatepic = 0
    EndIf
    GUICtrlSetData($Xcor, "X = " & $aCPos[0])
    GUICtrlSetData($Ycor, "Y = " & $aCPos[1])
    GUICtrlSetData($Wcor, "W = " & $aCPos[2])
    GUICtrlSetData($Hcor, "H = " & $aCPos[3])
    EndIf
    EndIf

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

    If $msg = $GUI_EVENT_CLOSE Then Exit

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

    Select
    Case $msg = $Buton
    $VarPic = FileOpenDialog("Bild", -1, "Bild (*.jpg;*.bmp)")
    If Not @error Then GUICtrlSetImage($pic, $VarPic)
    Case $msg = $Butonsave
    ;toDo
    EndSelect
    WEnd

    [/autoit]

    EDIT:
    Die linke Maustaste = Bild bewegen
    Die rechte Maustaste = Bildgröße ändern

    2 Mal editiert, zuletzt von getdot (2. August 2011 um 23:21) aus folgendem Grund: Info hinzufügen

  • Und was stimmt da nun nicht? Also mal davon abgesehen, dass dein Quellcode nahezu unlesbar ist dank fehlenden Einrückungen und extremster Verschachtelung funktioniert das doch im Prinzip alles.
    Bei mir lässt sich das Bild problemlos bewegen, resizen und die neuen Werte werden in den flackernden Labeln angezeigt. Also so wie es sein soll. ?(