Zohar

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

13 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



IMO Its not possible


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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
1 person likes this

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

Brings to mind a quote from somewhere. :blink:

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

:thumbsup:

:muttley:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites

Thanks Melba :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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


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

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

1 person likes this

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

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)

.

1 person likes this

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.

Share this post


Link to post
Share on other sites

SmOke_N,

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

M23

1 person likes this

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