CodeItBetter Programming Another VB Programming Blog

How to disable builtin right click context menu in text box

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'Controls - How to disable builtin right click context menu in text box
'In form:

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, _
    ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
 
Private Sub Form_Load()
    ' Subclass to ignore the context menu.
    OldWindowProc = SetWindowLong(Text1.hWnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
 
'In module:

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
Public OldWindowProc As Long
 
'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
    If msg <> WM_CONTEXTMENU Then NewWindowProc = CallWindowProc(OldWindowProc, hWnd, msg, _
        wParam, lParam)
End Function
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.