By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,529 Members | 923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,529 IT Pros & Developers. It's quick & easy.

Mouse movements in form

P: 15
Good morning folk,

a quick question to anyone who can help.

i am working on a program and i am using the below code to simulate mouse movement to certain
co-ords, but the thing is the co-ords 0 , 0 refer to the position at the very top left of the monitor.
what i want is for the co-ords 0 , 0 to refer to the top left in my form so the mouse clicks and
movements stay inside the form.

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
  2. Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  3. Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
  4. Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  5. Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
  6. Public Type PointAPI
  7.     x As Long
  8.     y As Long
  9. End Type
  10. Public Type RECT
  11.     Left As Long
  12.     Top As Long
  13.     Right As Long
  14.     Bottom As Long
  15. End Type
any help will be much appriciated


Sep 18 '07 #1
Share this Question
Share on Google+
2 Replies

P: 15
do i have to set my active form as an object ? and then make the active selection my form or something ?
Sep 18 '07 #2

P: 1,977
do i have to set my active form as an object ? and then make the active selection my form or something ?
i think you are looking for

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  3. End Sub
In the above form mouse move event you can get form mouse X and Y position in X As Single, Y As Single parameters.
Sep 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.