Results 1 to 7 of 7

Thread: Disabling Mouse Click

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274

    Disabling Mouse Click

    I want to disable mouse clicks and double clicks on a form or a control, anybody has any idea about how to do it?

  2. #2
    Megatron
    Guest
    If you want to truley disable them, then you can do so with subclassing, but I don't think that would be necessary here. If you want to ignore them, then simply don't place anything in their events. For example:
    Code:
    Private Sub Command1_Click()
        '< -- There is no code here, so nothing executes when it's clicked
    End Sub
    Or if you want to disable it at certian times, you could use a combination of a boolean flag, and the Exit Sub statement.
    Code:
    Private Sub Command1_Click()
        If bFlag = True Then Exit Sub
        MsgBox "Clicked"
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Actually the problem is that I have an activex control, and when it is double clicked, the name of the author appears in a msgbox, I want to disable it, so i think i would need to subclass it first.

  4. #4
    Megatron
    Guest
    Add 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
    Const GWL_WNDPROC = (-4)
    Const WM_LBUTTONDBLCLK = &H203
    
    Global 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_LBUTTONDBLCLK 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 to your Form
    Code:
    Private Sub Form_Load()
        SubClassWnd MyCtl.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd MyCtl.hwnd
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Thanks a lot, but no there is another problem, the control hasnt got any hWnd property. What do I do now?

  6. #6
    Megatron
    Guest
    Use the FindWindowEx API function to get the handle.

  7. #7
    Megatron
    Guest
    Here's an example.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    'Usage
    
    handle = FindWindowEx(0, 0, "ClassName", "WindowName")
    Use a tool like Spy++ to get the classname, and the window name should be the caption of the control.

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