PDA

Click to See Complete Forum and Search --> : Disabling Mouse Click


wasiq
May 17th, 2001, 07:00 AM
I want to disable mouse clicks and double clicks on a form or a control, anybody has any idea about how to do it?

Megatron
May 17th, 2001, 07:27 AM
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:

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.

Private Sub Command1_Click()
If bFlag = True Then Exit Sub
MsgBox "Clicked"
End Sub

wasiq
May 17th, 2001, 10:36 AM
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.

Megatron
May 17th, 2001, 10:41 AM
Add to a Module

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

Private Sub Form_Load()
SubClassWnd MyCtl.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd MyCtl.hwnd
End Sub

wasiq
May 17th, 2001, 11:55 AM
Thanks a lot, but no there is another problem, the control hasnt got any hWnd property. What do I do now?

Megatron
May 17th, 2001, 05:47 PM
Use the FindWindowEx API function to get the handle.

Megatron
May 17th, 2001, 05:50 PM
Here's an example.

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.