Results 1 to 3 of 3

Thread: Disable mouse button

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Question Disable mouse button

    How can I disable right button or left button of my mouse by VB codes or Win API ?

  2. #2
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    This is code to disable the Mouse completely...
    Otherwise, you can write your own code in the MouseUp or MouseDown events to test the Button parameter (1=left, 2=right).
    Code:
    '
    'This form needs two Command Buttons...
    '
    Private Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
    Private Sub Form_Load()
      Command1.Caption = "Limit Cursor Movement"
      Command2.Caption = "Release Limit"
    End Sub
    Private Sub Command1_Click()
      'Limits the Cursor movement to within the form.
      Dim Client As RECT
        
      ShowCursor 0&
      SetRect Client, 0, 0, 0, 0
      ClipCursor Client
    End Sub
    Private Sub Command2_Click()
      'Releases the cursor limits
      ClipCursor ByVal 0&
      ShowCursor 1&
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
      'Releases the cursor limits
      Command2_Click
      End
    End Sub

  3. #3
    Guest
    Remember: The MouseDown and MouseUp events occur after the buttons are clicked. If you want to truley disable them then you should subclass the WM_RBUTTONDOWN message.

    Add the following to a Module.
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const GWL_WNDPROC = (-4)
    Private Const WM_RBUTTONDOWN = &H204
    Private Const MK_RBUTTON = &H2
    
    Public WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If wMsg = WM_RBUTTONDOWN And wParam = MK_RBUTTON Then Exit Function
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld
        WndProcOld = 0
    End Sub
    Add the following to a Form.
    Code:
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width