-
How to call the api clipcursor to fix mouse in the region?
hi,I want to call the api function clipcursor to fix mouse in the region on a picturebox. But it has no effction. I don't know why it is.My code is following:
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long
Dim D As RECT
Private Sub Form_Load()
Picture1.Scale (-10, 10)-(10, -10)
D.left = -8: D.top = 8: D.right = 8: D.bottom = -8
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
dim t as long
t = ClipCursor(D)
End Sub
Please give me guide about it. Thanks a lot.
xuliangchu
-
Try this
Code:
Option Explicit
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Private Sub cmdClip_Click()
' Confines the cursor temporarily to inside of a picture control
Dim r As RECT ' confinement rectangle
Dim retval As Long ' return value
retval = GetWindowRect(Picture1.hwnd, r) ' put window's coordinates into r
retval = ClipCursor(r) ' confine the cursor to the boundries defined in r
End Sub
Private Sub cmdUnclip_Click()
' Unconfine the cursor (actually...confine it to the size of the desktop)
Dim r As RECT, retval As Long
Dim deskhWnd As Long ' the handle of the desktop window
deskhWnd = GetDesktopWindow() ' get handle of the desktop window
retval = GetWindowRect(deskhWnd, r) ' put window's coordinates into r
retval = ClipCursor(r) ' "confine" the cursor to the entire screen
End Sub
-
Here is an example in the FreeVBCode lib. that might be useful.
Keep Mouse Cursor Inside a Form or Control
Similar Threads
-
By Spurvey in forum VB Classic
Replies: 1
Last Post: 04-24-2005, 02:53 AM
-
By Flavio Hualpa in forum VB Classic
Replies: 0
Last Post: 02-27-2002, 07:11 PM
-
By Nikki in forum authorevents.mitchell
Replies: 1
Last Post: 10-18-2000, 05:03 PM
-
By BIG T in forum VB Classic
Replies: 16
Last Post: 05-13-2000, 12:40 AM
-
By Mike in forum VB Classic
Replies: 2
Last Post: 04-24-2000, 03:30 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|