Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
1 Module, 1 textbox
In Module :
Option Explicit
Public OldWindowProc As Long
Private 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
Public 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_USER = &H400
' 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
In Form :
Option Explicit
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
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444