Terenz Posted December 26, 2013 Posted December 26, 2013 (edited) Fast question, i need to get the control size-position but before showing the GUI: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form = GUICreate("Form", 150, 150, -1, -1) $Button = GUICtrlCreateButton("Button", 8, 8, 75, 25) $aPos = ControlGetPos("", "", $Button) If @error Then MsgBox(0, "Error", @error) ; <<<< I want to check here the control stats but give me error GUISetState(@SW_SHOW) $aPos = ControlGetPos("", "", $Button) ; <<<< here work but is too late If @error Then MsgBox(0, "Error", @error) Else MsgBox(0, "Window Stats:", "Position: " & $aPos[0] & "," & $aPos[1] & @CRLF & "Size: " & $aPos[2] & "," & $aPos[3]) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Maybe some WinAPI or GDI+ function can help? Thanks Edited December 26, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength
Moderators Melba23 Posted December 26, 2013 Moderators Posted December 26, 2013 Terenz,As you know where the control is located within the GUI client area, I assume you want the position in absolute coords. If that is the case then _WinAPI_ClientToScreen should do the trick:$Form = GUICreate("Form", 150, 150, -1, -1) $Button = GUICtrlCreateButton("Button1", 8, 8, 75, 25) Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData($tPoint, "X", 8) DllStructSetData($tPoint, "Y", 8) _WinAPI_ClientToScreen($Form, $tPoint) ConsoleWrite(DllStructGetData($tPoint, "X") & " - " & DllStructGetData($tPoint, "Y") & @CRLF) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndThe coords match with those obtained by the AutoIt Window Info tool once the GUI is visible. Just for interest, why do you need this information? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution Terenz Posted December 26, 2013 Author Solution Posted December 26, 2013 Melba before your post i have found the ControlGetPos work before the GUI show if i'll put the name of the GUI inside the function #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form = GUICreate("Form", 150, 150, -1, -1) $Button = GUICtrlCreateButton("Button", 8, 8, 75, 25) $aPos = ControlGetPos("Form", "", $Button) ; <<< before was ControlGetPos("", "", $Button) If @error Then MsgBox(0, "Error", @error) Else MsgBox(0, "Window Stats:", "Position: " & $aPos[0] & "," & $aPos[1] & @CRLF & "Size: " & $aPos[2] & "," & $aPos[3]) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd LOL sorry and thanks anyway for your contribute ( P.S i wat ot check the size if > number then resize it but before gui showing ) Nothing is so strong as gentleness. Nothing is so gentle as real strength
DatMCEyeBall Posted December 26, 2013 Posted December 26, 2013 You should use the handle to the window, just in case another window is open with the same name: $aPos = ControlGetPos($Form, "", $Button) But I don't think it would make much of a difference... "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation
Moderators Melba23 Posted December 26, 2013 Moderators Posted December 26, 2013 Terenz,If you need to know how big to make a control to fit a certain text then the StringSize UDF in my sig is exactly what you need. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now