How to call the api clipcursor to fix mouse in the region?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How to call the api clipcursor to fix mouse in the region?

  1. #1
    Join Date
    Sep 2004
    Posts
    96

    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

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Here is an example in the FreeVBCode lib. that might be useful.
    Keep Mouse Cursor Inside a Form or Control

Similar Threads

  1. Old GetNumTasks() API Call
    By Spurvey in forum VB Classic
    Replies: 1
    Last Post: 04-24-2005, 02:53 AM
  2. API call in VB.NET
    By Flavio Hualpa in forum VB Classic
    Replies: 0
    Last Post: 02-27-2002, 06:11 PM
  3. Need to call API functions
    By Nikki in forum authorevents.mitchell
    Replies: 1
    Last Post: 10-18-2000, 05:03 PM
  4. Mouse X,Y position with API call
    By BIG T in forum VB Classic
    Replies: 16
    Last Post: 05-13-2000, 12:40 AM
  5. NetUserEnum Api
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center