Jump to content

Recommended Posts

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
  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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.

  Reveal hidden contents

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

Posted

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

  • Moderators
Posted

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:

  Reveal hidden contents

 

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
  • Moderators
Posted

Zohar,

 

  Quote

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:

  Reveal hidden contents

 

  • Moderators
Posted

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.

  • Moderators
Posted

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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