Results 1 to 7 of 7

Thread: Disable DblClick event !

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Bahrain
    Posts
    41
    Is there a way to disable DblClick event on ActiveX control ?

    The problem is, if I click on a control, MouseDown will run first, then MouseUp, but the next click, DblClick will run instade of MouseUp and MouseDown.

    I want in all cases, MouseDown and MouseUp to run

  2. #2
    Megatron
    Guest
    Double click will only run if you press the mouse fast enough.

  3. #3
    Megatron
    Guest
    I guess you could always subclass your Form.

    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 a Form.
    Code:
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Bahrain
    Posts
    41
    Thanks Megatron for your reply..

    Your code has diabled DblClick event but still i can not make MouseDown and MouseUp runs fast..

    What I want is, even if you double click on a form (or
    picturebox) the MouseDown and MouseUp should run,
    like this : -

    Click (1)
    >> MouseDown
    >> MouseUp
    Click(2)
    >> MouseDown
    >> MouseUp

    But it VB works like this: -
    Click(1)
    >> MouseDown
    >> MouseUp
    Click(2)
    >> DblClick <-- here is the problem !

    Plz help..

  5. #5
    Megatron
    Guest
    Just send the WM_LBUTTONDOWN message on the double click message.

    Replace the former Module with this one:
    Code:
    Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    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
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    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
            PostMessage hwnd, WM_LBUTTONDOWN, 0, 0
            Exit Function
        End If
        
        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

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Bahrain
    Posts
    41
    It works nicly... thanks..

    Btw.. What is sub classing excactly ? it seams to be powerfull...

    Where can i get good resource of sub classing ?

    Thanks again megatron..

    (I will add new thread for SubClassing !)
    Last edited by hassan; Apr 14th, 2001 at 05:03 AM.

  7. #7
    Megatron
    Guest
    Basically, subclassing allows to intercept messages. This can be useful, because VB doesn't provide even for all messages. It's also useful because you can override VB's commands. For example, you can intercept the Right-Click in a TextBox, so the context menu doesn't pop-up.

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