My book Custom Controls Library disables context menus to implement
several custom controls.
Warning: Subclassing is dangerous. The debugger does not work well when a new
WindowProc is installed. If you halt the program instead of unloading its
forms, it will crash and so will the Visual Basic IDE. Save your work often!
Don't say you weren't warned.
When the form loads, subclass to watch for WM_CONTEXTMENU messages.
|
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
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As _
Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_CONTEXTMENU = &H7B
' Pass along all messages except the one that
' makes the context menu appear.
Public Function NewWindowProc(ByVal hWnd As Long, ByVal msg _
As Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
Const WM_NCDESTROY = &H82
' If we're being destroyed,
' restore the original WindowProc.
If msg = WM_NCDESTROY Then
SetWindowLong _
hWnd, GWL_WNDPROC, _
OldWindowProc
End If
If msg <> WM_CONTEXTMENU Then _
NewWindowProc = CallWindowProc( _
OldWindowProc, hWnd, msg, wParam, _
lParam)
End Function
|