Determining mouse position x y 
Author Message
 Determining mouse position x y

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.*-*-*.com/
Before you buy.



Sat, 01 Jun 2002 03:00:00 GMT  
 Determining mouse position x y
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



Quote:
> 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.



Sat, 01 Jun 2002 03:00:00 GMT  
 Determining mouse position x y
Nicole,

Thanks! It worked great.

--
Regards,
Randy Shore
Data Design
805.494.3439



Quote:
> 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"

- Show quoted text -

Quote:
> (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



> > 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.

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


Sun, 02 Jun 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Determine position of textbox.

2. Determining cursor position in a table

3. Determining ENTER positions in a string.

4. Determine the position of a record in a dynaset

5. Determining cursor position in a textbox

6. Determining Position in Richtextbox

7. How do you determine textbox cursor position?

8. How do I determine the Cursur Position in an RTF

9. Help - how to determine cursor position?

10. Determine Position of Component

11. Tricky one - mouse position anywhere...

12. Detecting Mouse Position x y

 

 
Powered by phpBB® Forum Software