[AccessD] Screen position of mouse. ALMOST SOLVED....

Erwin Craps Erwin.Craps at ithelps.be
Fri Sep 19 09:30:10 CDT 2003


Haha, 

I just implemented that code, but indeed left was ok but top was about 3
to 4 cm below my cursor....
But I got the picture and I'm driving in the right lane now...

Thx

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart
McLachlan
Sent: Friday, September 19, 2003 3:55 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Screen position of mouse.


On 19 Sep 2003 at 14:58, Erwin Craps wrote:

> I can't find how to know the postition of the mouse on the screen.
>  
> I have a pop-up form I want to pop-up at the same place as where the 
> mouse cursor is at that time. So I want to put put the code in the 
> on_open event of the pop-up form in question
>  
> lngMouseLeft = ???.Left
> lngMouseTop = ???.Top
>  
> me.move lngMouseLeft, lngMouseTop
> 

It gets quite tricky.  You can find the current mouse position in 
pixels easily enough:

In a module:
Type POINTAPI
  x As Long
  y As Long
End Type
Declare Function GetCursorPos Lib "USER32.DLL" (lpPoint As POINTAPI) 
As Long

In your event:
Dim mptr As POINTAPI
Dim result As Long
result = GetCursorPos(mptr)
Msgbox "Mouse is at Screen position " & mptr.x & " : " & mptr.y & " 
in pixels"

However, that doesn't really help.

Forms are positioned in twips relative to their parent (usually the 
main application window).

You need to get a handle to the parent window  using the 
GetActiveWindow() and GetWindow() API calls then get the location of 
that window using GetWindowPlacement.

Then you need to convert these pixel figures to twips and use 
Docmd.MoveSize to place the from at an appropriate position within 
it's parent.


 
-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list