Access97 Window Coordinates

D

Dave Cousineau

does anyone know how i can get screen coordinates for
forms, controls or that access window itself? i can use
DoCmd.MoveSize to change the position of a form using
relative coordinates, but not absolute screen coordinates,
or even absolute access coordinates

(what i want to do is make a form popup based on where the
user clicked. if i could just get current x, y coordiantes
for the controls the user is clicking that would suffice.)

maybe i have to resort to using a Win32API function, but
if so which one?

much thanks for your help
 
A

Adrian Jansen

You probably need a windows API call(s). The whole point of Windows is that
all coordinates are relative to their container. So you need to go back up
through each container getting the relative coords of each until you end up
at the screen. Ok if you only have one screen. Think of the problems you
will encounter on systems with multiple screens, even with different
resolutions, with containers spread across some of them. Dont laugh, it is
possible to have this scenario, and Windows handles it quite well.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
D

Dan Artuso

Hi,
You can try the GetCursorPos API which should return
the screen coordinates.

Put this in a standard module:
Public Type POINTAPI
X As Long
Y As Long
End Type

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

You can call it from the click event of the control:

Dim Pt As POINTAPI

GetCursorPos Pt
MsgBox Pt.X
MsgBox Pt.Y

I tried it out from the click event of a command button which gives
me the coordinates of where the user cliked.

Download the API Guide from:
http://www.mentalis.org/

If you want more complex examples.
 
D

Dave Cousineau

if i could somehow get relative coordinates that would be
great. i can get the coordinates for the mouse click
relative to the control, control coordinates realtive to
the form, but can you get the form's coordiantes relative
to the access window, and then finally the access window
relative to the screen? even missing one link in the chain
will make it ineffective.

i think Dan Artuso's example will suffice, but ill have to
test it tomorrow.

much thanks guys
 
P

PC Datasheet

Dave,

Put the following in the MouseDown event of the form:

MsgBox X & " " & Y

The message box will display the X,Y coordinates in twips of the point on the
form you clicked on.
 
A

Adrian Jansen

Good one Dan !

Works even on a multiple screen system. Returns the coordinates of a point
relative to the primary screen top left. So you can get negative coords for
points on a secondary screen to the left/above the primary, but it still
makes sense.


--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top