Sign in to follow this  
Followers 0
Tomb

getting position of child window

7 posts in this topic

#1 ·  Posted (edited)

How can i get the position of a child window which was made a child window with

DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $CHILD, "hwnd", $GUI)

ControlGetPos - does not work

WinGetPos - also does not work

Edited by Tomb

Share this post


Link to post
Share on other sites



im still looking for a solution.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try: Opt("WinSearchChildren", 1) before you use WinGetPos($CHILD)

Edit:

Keep in mind, $CHILD has to be a hwnd.

Edited by SmOke_N

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

i gave it a try. this is the test i used.

but it doesnt seem to work correctly.

#Include <GUIConstants.au3>
#Include <WindowsConstants.au3>

$Parent = GUICreate("parent window", 300, 300, -1, -1, BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPCHILDREN,$WS_EX_LAYERED), -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")
Opt("WinSearchChildren", 1)
Opt("GUIOnEventMode",1)
GuiSetState(@SW_SHOW, $Parent)

$Child = GUICreate("child window", 200, 200)
$Button = GUICtrlCreateButton("push the button", 50, 50, 50, 50)
GUICtrlSetOnEvent(-1, "Button")
GUISetState(@SW_SHOW, $Child)

DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Child, "hwnd", $Parent)
ControlMove("", "", $Child, 0, 0, 200, 200)


While 1
    sleep(10)
WEnd



Func Button()
    $CPOS = ControlGetPos("", "", $Child)
    MsgBox(0, "", $CPOS[0] & " , " & $CPOS[1] & " , " & $CPOS[2] & " , " & $CPOS[3])
EndFunc


Func ExitScript()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

hmm i just noticed that i was still using CotrolGetPos().

going to try WinGetPos() with the Opt("WinSearchChildren", 1)

edit:

it seems that WinGetPos with Opt("WinSearchChildren", 1) works correctly.

however, most of the child GUI's i am checking position of do not have a window title.

if only there were a similar function to WinGetPos that could use control Id as a perameter.

edit 2:

now im looking at _WinAPI_GetClientRect but not entirely sure if it will work.

Edited by Tomb

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hmm i just noticed that i was still using CotrolGetPos().

going to try WinGetPos() with the Opt("WinSearchChildren", 1)

edit:

it seems that WinGetPos with Opt("WinSearchChildren", 1) works correctly.

however, most of the child GUI's i am checking position of do not have a window title.

if only there were a similar function to WinGetPos that could use control Id as a perameter.

edit 2:

now im looking at _WinAPI_GetClientRect but not entirely sure if it will work.

I don't really see your issue here. GUICreate() returns a handle. So ControlGetPos() if it is a child, using the parents handle as the first param should work fine. I have no clue why you are leaving the first parameter blank of ControlGetPos().

At any rate.

Func _Win_GetChildPos($h_parent, $h_child)
    Local $h_wnd = ControlGetHandle($h_parent, "", $h_child)
    Return WinGetPos($h_wnd)
EndFunc
Should solve your problem all together with or without the Opt.

Edit:

Had redundant code in there.

Edited by SmOke_N

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

very nice, with ControlGetHandle() and WinGetPos() i can return the correct position.

thank you SmOke_N :)

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