Jump to content

Get window coordinates of a pic control


Will66
 Share

Recommended Posts

How can i retrieve the windows coordinates of a gui control item.

For example get a pic controls left and top position relative to the window not the gui:

#include <GUIConstants.au3>

$Form1 = GUICreate("Active Screen", 633, 454, 193, 115,$WS_OVERLAPPEDWINDOW + $WS_VISIBLE)
Dim $widthTh,$heightTh
$Height1=300
$Width1=300
$Obj1_ctrl = GUICtrlCreatePic("dino.jpg",120, 32,$Width1,$Height1)
$size = WinGetPos("")
;MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])
$myLeft=$size[0] + 120 ; not correct by about 4 pixels
$myTop=$size[1] + 32 ; not correct by about 30 pixels
;MsgBox(0, ":", $myLeft & " " & $myTop)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
                
    EndSwitch
WEnd
Link to comment
Share on other sites

ControlGetPos()

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

No that gives me the position of the control relative to the gui:

$Obj1_ctrl = GUICtrlCreatePic("dino.jpg",120, 32,$Width1,$Height1)

$size = WinGetPos("")

$pos = ControlGetPos("Active Screen", "", $Obj1_ctrl)

MsgBox(0, "Window Stats:", "POS: " & $pos[0] & "," & $pos[1] & " SIZE: " & $pos[2] & "," & $pos[3] )

ie 120, 32, 300, 300

Edit: Perhaps i should say relative to the screen, i'm trying to take a screen shot and need the screen coordinates of the control

Edited by Will66
Link to comment
Share on other sites

For example get a pic controls left and top position relative to the window not the gui:

O.K. so what's the difference between the window and the gui?

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

DLLCall/SystemParametersInfo to get the Window Caption and Frame sizes (heights / widths) or...

WinGetPos MATH with WinGetClientSize...

Lar.

Thanx Lar, I figured i'd need to do some math, but for the life of me i was blind to WinGetClientSize function.

I'll experiment with the dll call too,

Its really cool to see some of your work using gdi32.dll and user32.dll, its opened my eyes to a whole new world of possibilities.....

it'd be great to see some of those dll calles included with autoit as <includes> with a call to it by a function.....but then i guess i'd never know they existed :whistle:

cheers.

Link to comment
Share on other sites

bump:

i'm trying to take a screen shot and need the SCREEN (left/top) coordinates of the pic control.....

heeeewwlp......

here is what you need. Add to your code at the right place!!

#include <Array.au3>

$handle = ControlGetHandle("Active Screen", "", "Static1")

If @error Then  
    MsgBox(0,"ERROR","No Handle found")
    Exit
EndIf


$lpRect = DllStructCreate("int;int;int;int")
$ret = DllCall("user32.dll","int","GetWindowRect","hwnd",$handle,"ptr",DllStructGetPtr($lpRect))

If @error Then
    MsgBox(0,"","DllCall error")
    Exit
EndIf

Dim $coords[4]

$coords[0] = DllStructGetData($lpRect,1)
$coords[1] = DllStructGetData($lpRect,2)
$coords[2] = DllStructGetData($lpRect,3)
$coords[3] = DllStructGetData($lpRect,4)

_ArrayDisplay($coords,"Coordinates")
Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
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
 Share

  • Recently Browsing   0 members

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