FAQsHow do I get the global coordinates of a window?There are many times that you want to save the global coordinates of a window so that you may reopen it for your user when the program is restarted. This sample program includes a function named
fn getGlobalWndRect(wNum as long, r as ^rect)
that may be pasted into your code and used for that purpose.
This function requires two parameters. The first is the window number that you wish to capture. This does not need to be the active window, but it does need to be a window that is currently open. The second is a rectangle. The rectangle must be one that you have dimensioned in your function or, alternatively, it may be a global. If you are using a rect that was passed to your function as a pointer, precede it with a pound symbol before passing it as a parameter.
appearance window 1 , "you need my global coords"
appearance window 2 , "print window 1's coords here"
Text 0,12,0,2
// this calculates the global postion of any window
local fn getGlobalWndRect(wNum as long, r as ^rect)
dim as CGrafPtr @ port
dim as long result , oldOut
dim as WindowRef w
oldOut = window ( _outputWnd )
window output ( wNum )
Call GetPort(port)
result = fn GetPortBounds( port, #r )
Call LocalToGlobal ( r.top )
Call LocalToGlobal ( r.bottom )
window output ( oldOut )
end fn
// this shows the global position of window 1 every second
local fn doTimer
dim as rect r
dim as long oldOut
oldOut = window ( _outputWnd )
window output 2
cls
fn getGlobalWindowRect ( 1 , r )
print "Move or resize the other window and watch the coordinates change here"
print r
window output oldOut
end fn
on timer ( 1 ) fn doTimer
do
handleEvents
until 0
|