Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determining mouse position x y

10 views
Skip to first unread message

Randy at Data Design

unread,
Dec 14, 1999, 3:00:00 AM12/14/99
to
I am trying to determine the mouse position when the user clicks so
that I can set the top and left properties of a pop-up form to open in
relation to the mouse-click coordinates. I know that this will require
API calls, and I only have limited experience working with Windows API.

At Dev Avish's site, I found code to align the tops of two forms,
(www.mvps.org/access/forms/frm0042.htm) but I can't figure out how to
adapt this code to my purposes.


--
TIA,
Randy Shore
Data Design
805.494.3439


Sent via Deja.com http://www.deja.com/
Before you buy.

Nicole Calinoiu

unread,
Dec 14, 1999, 3:00:00 AM12/14/99
to
Randy,

You can use a call to the GetCursorPos API function to retrieve the mouse.
You'll first need to declare the point coordinate type used by the API call
then declare the function call itself. You'll also need to declare the
ScreenToClient API call since GetCursorPos returns a position in the screen
coordinate system, which you'll have to convert to the Access MDI window
coordinate system before moving your form:

Public Type POINTAPI 'used for GetCursorPos API function
x As Long
y As Long
End Type

Public Declare Function apiGetCursorPos Lib "user32" Alias "GetCursorPos"
(lpPoint As POINTAPI) As Long
Public Declare Function apiScreenToClient Lib "user32" Alias
"ScreenToClient" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long

The simplest example of moving a form to the mouse coordinates would involve
the following restrictions:

1. Move the upper left corner to the current mouse position (as opposed to
some prior mouse position).
2. Ignore the fact that positioning the form in this way might cause all or
part of the form to be positioned outside the current Access window
rectangle.

The following function will accomplish this task:

Public Sub MoveFormToMouse(ByVal frmToMove As Form)

Dim fwToMove As clFormWindow
Dim ptCursor As POINTAPI

apiGetCursorPos ptCursor

Set fwToMove = New clFormWindow
With fwToMove
.hWnd = frmToMove.hWnd

apiScreenToClient .Parent.hWnd, ptCursor

.Left = ptCursor.x
.Top = ptCursor.y
End With

Set fwToMove = Nothing

End Sub

HTH,
Nicole

"Randy at Data Design" <vtas...@my-deja.com> wrote in message
news:835mif$5lv$1...@nnrp1.deja.com...

Randy at Data Design

unread,
Dec 15, 1999, 3:00:00 AM12/15/99
to
Nicole,

Thanks! It worked great.

--
Regards,


Randy Shore
Data Design
805.494.3439

In article <uZVK9zqR$GA.255@cppssbbsa04>,

0 new messages