Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleDisable a TextBox's context menu
KeywordsTextBox, right click, popup, context menu
CategoriesControls, API
 
When the form loads, the program uses SetWindowLong to give the TextBox a new WindowProc. When the form unloads, the program restores the original WindowProc. This is important. If it does not do this, the program will be unable to properly unload the subclassed control and will crash.
 
Private Sub Form_Load()
    ' Set the control's new WindowProc.
    OldWindowProc = SetWindowLong( _
        txtMenuDisabled.hWnd, GWL_WNDPROC, _
        AddressOf NoPopupWindowProc)
End Sub

' Restore the original WindowProc.
Private Sub Form_Unload(Cancel As Integer)
    SetWindowLong _
        txtMenuDisabled.hWnd, GWL_WNDPROC, _
        OldWindowProc
End Sub
 
The new WindowProc simply calls the original WindowProc to process all messages except the WM_CONTEXTMENU message that makes the context menu appear.
 
' Pass along all messages except the one that
' makes the context menu appear.
Public Function NoPopupWindowProc(ByVal hWnd As Long, ByVal _
    msg As Long, ByVal wParam As Long, ByVal lParam As _
    Long) As Long
Const WM_CONTEXTMENU = &H7B

    If msg <> WM_CONTEXTMENU Then _
        NoPopupWindowProc = CallWindowProc( _
            OldWindowProc, hWnd, msg, wParam, _
            lParam)
End Function
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated