Sign in to follow this  
Followers 0
Terenz

Control size ( not ControlGetPos )

5 posts in this topic

#1 ·  Posted (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 by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites



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
WEnd
The 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? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0