Jump to content
Sign in to follow this  

ClientToScreen not needed if you can get control handle

Recommended Posts


Not sure if this is the right place, but here it goes.

In the help file example for GUICtrlCreateContextMenu, the second example makes use of a function ClientToScreen(), this takes the coords of a control within a parent window and figures out where the exact coords are on the screen.

But you could accomplish the same results by using WinGetPos on the control's handle.

Func _ControlGetScreenPos($hWnd, $sText, $iCtrl)
    Local $hCtrl = ControlGetHandle($hWnd, $sText, $iCtrl)
    Return WinGetPos($hCtrl)

WinWait('Untitled - Notepad')

$aClient = ControlGetPos('Untitled', '', 'Edit1')
$aScreen = _ControlGetScreenPos('Untitled', '', 'Edit1')

MsgBox(0, 'Coords of Edit control', 'Client: ' & $aClient[0] & 'x' & $aClient[1] & @LF & _
    'Screen: ' & $aScreen[0] & 'x' & $aScreen[1])oÝ÷ Ø׶¡wb*.ßÚÞ$x¢¶§ëh"×+y«^uÊ'¶º%ßۢݲ+wöǯzw²'«jëh×6GUICreate('', 200, 200)
$bt = GUICtrlCreateButton('Hello', 50, 50, 100, 100)

$hCtrl = GUICtrlGetHandle($bt)
$aPos = WinGetPos($hCtrl)

MsgBox(0, 'Coords', $aPos[0] & 'x' & $aPos[1])

Well, I thought it was neat anyway.

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.