Jump to content

[Solved] How to Use ControlGetPos() When I Already Have a Handle to the Control


Zohar
 Share

Recommended Posts

Hi

 

Assume this case:

I got a handle to a control, in $hControl,

and I now want to use ControlGetPos(), but without supplying it again the Window Name(or class), and the Control ClassNN,

but simply supplying $hControl.

 

How can I do it?

 

Thank you

Edited by Zohar
Link to comment
Share on other sites

  • Moderators

Zohar,

Of course it is possible - complicated, but possible: ;)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

GUISetState()

; Using ControlGetPos
$aControlGetPos = ControlGetPos($hGUI, "", $cButton)
_ArrayDisplay($aControlGetPos, "ControlGetPos", Default, 8)

; Get handle
$hHandle = GUICtrlGetHandle($cButton)
; But using WinGetPos gives you absolute coords
$aWinGetPos = WinGetPos($hHandle)
_ArrayDisplay($aWinGetPos, "WinGetPos - Basic", Default, 8)

; So you need to convert them to client coords
Local $tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aWinGetPos[0])
DllStructSetData($tPoint, "Y", $aWinGetPos[1])
_WinAPI_ScreenToClient($hGUI, $tPoint)
$aWinGetPos[0] = DllStructGetData($tPoint, "X")
$aWinGetPos[1] = DllStructGetData($tPoint, "Y")
_ArrayDisplay($aWinGetPos, "WinGetPos - Converted", Default, 8)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Brings to mind a quote from somewhere. :blink:

Melba23 making the impossible possible since August 2008! :sorcerer:

:thumbsup:

:muttley:

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Hi Melba

Thank you very much for the example,

but I think my question was not completely understood.

My appology, allow me to sharpen my explanation abit.

 

The window is not created by me via AutoIt, but is a 3rd party application's window.

 

Also,

my question is If the ControlGetPos() function can somehow get the Handle variable as a parameter,

and not to use additional code...

 

The reason I ask this, is because I remember some years ago that I read in the Help file,

that all functions of some type(I think all functions that work on a Window?) can also get a Handle, instead of the Window Title/Class.

Despite the fact that I'm sure that I read it in the help, I am not able to find it now..

Anyone knows where it is written?

 

Thank you

Link to comment
Share on other sites

  • Moderators

Zohar,

You can use a window's "handle" in place of its "title" - so in ControlGetPos you can identify the parent GUI by either. But when using that function the control must be identified by its "ControlID". So if all we have is a handle, we need to determine the ControlID - which is not very difficult as you can see: ;)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
$hHandle = GUICtrlGetHandle($cButton) ; Get control handle

GUISetState()

; Using ControlID
$aControlGetPos = ControlGetPos($hGUI, "", $cButton)
_ArrayDisplay($aControlGetPos, "ControlID", Default, 8)

; Using handle
$aControlGetPos = ControlGetPos($hGUI, "", _WinAPI_GetDlgCtrlID($hHandle)) ; Convert handle to ControlID
_ArrayDisplay($aControlGetPos, "Handle", Default, 8)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Is that what you wanted? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Melba:

Yes I understand now..

Thank you

BTW, do you know where in the Help file it is written? (that we can replace the Window Name with the Window Handle)

 

Trong:

You didn't read the answers people wrote here if you say it's impossible :)

Edited by Zohar
Link to comment
Share on other sites

  • Moderators

Zohar,

 

do you know where in the Help file it is written? (that we can replace the Window Name with the Window Handle)

At the bottom of the Window Titles and Text (Advanced) page. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

Maybe I'm missing something?  I've always just used the handle straight up.

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
$hHandle = GUICtrlGetHandle($cButton) ; Get control handle

GUISetState()

; Using ControlID
$aControlGetPos1 = ControlGetPos($hGUI, "", $cButton)
_ArrayDisplay($aControlGetPos1, "ControlID", Default, 8)

; Using handle
$aControlGetPos2 = ControlGetPos("", "", $hHandle)
_ArrayDisplay($aControlGetPos2, "Handle1", Default, 8)

$aControlGetPos3 = ControlGetPos($hHandle, "", "")
_ArrayDisplay($aControlGetPos3, "Handle2", Default, 8)

$aControlGetPos4 = ControlGetPos($hGUI, "", $hHandle)
_ArrayDisplay($aControlGetPos4, "Handle3", Default, 8)

.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

SmOke_N,

Well, well, well. We learn something new everyday. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...