I want to disable mouse clicks and double clicks on a form or a control, anybody has any idea about how to do it?
Printable View
I want to disable mouse clicks and double clicks on a form or a control, anybody has any idea about how to do it?
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:
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()
'< -- There is no code here, so nothing executes when it's clicked
End Sub
Code:Private Sub Command1_Click()
If bFlag = True Then Exit Sub
MsgBox "Clicked"
End Sub
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.
Add to a Module
Add to your FormCode: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
Code:Private Sub Form_Load()
SubClassWnd MyCtl.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd MyCtl.hwnd
End Sub
Thanks a lot, but no there is another problem, the control hasnt got any hWnd property. What do I do now?
Use the FindWindowEx API function to get the handle.
Here's an example.
Use a tool like Spy++ to get the classname, and the window name should be the caption of the control.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")