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
control size ermitteln in pixel
-
- [ offen ]
-
getdot -
2. August 2011 um 15:29 -
Geschlossen -
Erledigt
-
-
- Offizieller Beitrag
Du willst die Größe (in Pixel) von GUI-Elementen herausbekommen?
Dann hilft Dir vielleicht mein Bildschirm-Lineal (mm/cm) -
Braucht man keine UDF dazu, die Funktion controlgetpos() reicht völlig:
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>$Form1 = GUICreate("Form1", 625, 445, 192, 124)
[/autoit] [autoit][/autoit] [autoit]
$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)While 1
[/autoit]
$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 -
Erst einmal Danke für eure Antworten!
Braucht man keine UDF dazu, die Funktion controlgetpos() reicht völlig:
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
#include
#include
#include
#include
#include$Form1 = GUICreate("Form1", 625, 445, 192, 124)
[/autoit] [autoit][/autoit] [autoit]
$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)While 1
[/autoit]
$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
WEndDas stimmt nicht! Hier ein Script zum Testen
Spoiler anzeigen
[autoit]#include <GUIConstantsEx.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>Local $guiX = 600, $guiY = 400, $VarPic = @SystemDir & "\oobe\images\mslogo.jpg", $updatepic = 0
[/autoit] [autoit][/autoit] [autoit]
$gui = GUICreate("test", 610, 430, -1, -1)
$pic = GUICtrlCreatePic($VarPic, 10, 40, 200, 150)$Buton = GUICtrlCreateButton("Bild Laden", 10, 10, 80, 25)
[/autoit] [autoit][/autoit] [autoit]GUICtrlCreateGroup("Dots per inch", 95, 0, 250, 35)
[/autoit] [autoit][/autoit] [autoit]
$Xcor = GUICtrlCreateLabel("X = 10", 100, 15, 60, 15)
GUICtrlSetFont(-1, 10)$Ycor = GUICtrlCreateLabel("Y = 40", 160, 15, 60, 15)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetFont(-1, 10)$Wcor = GUICtrlCreateLabel("W = 200", 220, 15, 60, 15)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetFont(-1, 10)$Hcor = GUICtrlCreateLabel("H = 150", 280, 15, 60, 15)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetFont(-1, 10)$Butonsave = GUICtrlCreateButton("Bild Speichern", 360, 10, 80, 25)
[/autoit] [autoit][/autoit] [autoit]GUISetState()
[/autoit] [autoit][/autoit] [autoit]While 1
[/autoit] [autoit][/autoit] [autoit]
$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)If $aCPos[0] + $aMPosNew[0] - $aMPos[0] - 10 < 0 And $aCPos[1] + $aMPosNew[1] - $aMPos[1] - 40 < 0 Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, 10, 40)
$updatepic = 1
ExitLoopElseIf $aCPos[0] + $aMPosNew[0] - $aMPos[0] - 10 < 0 Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, 10, $aCPos[1] + $aMPosNew[1] - $aMPos[1])
$updatepic = 1
ExitLoopElseIf $aCPos[1] + $aMPosNew[1] - $aMPos[1] - 40 < 0 Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], 40)
$updatepic = 1
ExitLoopElseIf $aCPos[0] + $aMPosNew[0] - $aMPos[0] + $aCPos[2] > $guiX Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $guiX - $aCPos[2], $aCPos[1] + $aMPosNew[1] - $aMPos[1])
$updatepic = 1
ExitLoopElseIf $aCPos[1] + $aMPosNew[1] - $aMPos[1] + $aCPos[3] > $guiY Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], $guiY - $aCPos[3])
$updatepic = 1
ExitLoop
EndIfControlMove($gui, "", $pic, $aCPos[0] + $aMPosNew[0] - $aMPos[0], $aCPos[1] + $aMPosNew[1] - $aMPos[1])
[/autoit] [autoit][/autoit] [autoit]
$updatepic = 1
EndIf
Until Not _IsPressed("01")Do
[/autoit] [autoit][/autoit] [autoit]
$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)
ExitLoopElseIf $aCPos[2] + $aMPosNew[0] - $aMPos[0] < 5 Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], 5, $aCPos[3] + $aMPosNew[1] - $aMPos[1])
$updatepic = 1
$aCPosinput = ControlGetPos($gui, "", $pic)
ExitLoopElseIf $aCPos[3] + $aMPosNew[1] - $aMPos[1] < 5 Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], 5)
$updatepic = 1
$aCPosinput = ControlGetPos($gui, "", $pic)
ExitLoopElseIf $aCPos[0] + $aCPos[2] + $aMPosNew[0] - $aMPos[0] > $guiX Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $guiX - $aCPos[0], $aCPos[3] + $aMPosNew[1] - $aMPos[1])
$updatepic = 1
$aCPosinput = ControlGetPos($gui, "", $pic)
ExitLoopElseIf $aCPos[1] + $aCPos[3] + $aMPosNew[1] - $aMPos[1] > $guiY Then
[/autoit] [autoit][/autoit] [autoit]
ControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], $guiY - $aCPos[1])
$updatepic = 1
$aCPosinput = ControlGetPos($gui, "", $pic)
ExitLoop
EndIfControlMove($gui, "", $pic, $aCPos[0], $aCPos[1], $aCPos[2] + $aMPosNew[0] - $aMPos[0], $aCPos[3] + $aMPosNew[1] - $aMPos[1])
[/autoit] [autoit][/autoit] [autoit]
$updatepic = 1
EndIf
Until Not _IsPressed("02")If $updatepic = 1 Then
[/autoit] [autoit][/autoit] [autoit]
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
EndIfIf $msg = $GUI_EVENT_CLOSE Then Exit
[/autoit] [autoit][/autoit] [autoit]Select
[/autoit]
Case $msg = $Buton
$VarPic = FileOpenDialog("Bild", -1, "Bild (*.jpg;*.bmp)")
If Not @error Then GUICtrlSetImage($pic, $VarPic)
Case $msg = $Butonsave
;toDo
EndSelect
WEndEDIT:
Die linke Maustaste = Bild bewegen
Die rechte Maustaste = Bildgröße ändern -
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.