Jump to content
Sign in to follow this  
martin

_WInGetPosIn function

Recommended Posts

martin

If you need to resize or move child windows the WinGetPos function is awkward because the position returned is in screen coordinates, whereas WinMove uses coordinates relative to the parent client 0,0 position.

Authenticity pointed that out that ControlGetPos does the job but not for the position of a child in a child whereas this does.

; #FUNCTION# ================================================================================
  ; Name...........: _WinGetPosIn
  ; Description ...: Returns an array of coordinates for $childw with the position coordinates
  ;               relative to the 0,0 client area of $parentW
  ; Parameters  .... $childw the window handle or title whose position is required
  ;               $childText the text in the child window (can be "")
  ;               $parentw
  ;               $parentText
  ; On success 
  ;   returns an array with 4 elements
  ;    [x,y,childwidth,childheight]
  ;     where x,y is the position relative to the parent client area 0,0
  ; On failure 
  ;   returns 0 and sets @error to 1 
  ;   and sets @Extended to 1 if the $ChildW is not a window
  ;                         2 if $parentW is not a window
  ;                         3 if either window is minimized
  ;                         4 if failed to get coordinates for $parentw
  ; NOTE- It is not required that $childW is actually a child of $parentW
  ;     although this is when the function is most useful
  ;============================================================================================
        
        Func _WinGetposIn($parentW,$parentText,$childW,$childText="")
            Local $Result, $offset
            
            if Not WinExists($childw) then return seterror(1,1,0)
            if Not WinExists($parentw) then return seterror(1,2,0)
            
            If BitAND(WinGetState($childW), 16) Or BitAND(WinGetState($parentW), 16) Then Return seterror(1,3,0)
            
            $offset = dllstructcreate("int;int")
            DllCall("User32.dll", "int", "ClientToScreen", "hwnd", WinGetHandle($parentW,$parentText), "ptr", DllSTructGetPtr($offset))
            if @error then return seterror(1,4,0)
            
            $Result = wingetpos($childW, $childText)
            $Result[0] -= dllstructgetdata($offset,1)
            $Result[1] -= dllstructgetdata($offset,2)
            return $Result
        EndFunc

Use ControlGetPos unless you need the position of a window in a child window.

EDIT: Changed to make it the same format as ControlGetPos

mgrefWingetPosIn

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Authenticity

And what about ControlGetPos?

Share this post


Link to post
Share on other sites
martin

And what about ControlGetPos?

Well I never thought to use ControlGetPos for a child window, but now you say that It would be obvious. ^_^ I'll try it.

Yes, of course it works. Thanks authenticity. I'll leave the post as a monument to my stupidity.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
martin

Well I never thought to use ControlGetPos for a child window, but now you say that It would be obvious. ^_^ I'll try it.

Yes, of course it works. Thanks authenticity. I'll leave the post as a monument to my stupidity.

But then again I found that in the script I was using it ControlGetPosition desn't work for a window in a child window so I'm not quite so stupid maybe.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  

×