Well, I figured that out. Here is an alternate approach to completely disable the context menu, without any flaw.
Here I have used subclassing. So don't terminate your program using End statement or End button on toolbar.
Add a bas module and paste the following code in it.
___
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Declare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc&, ByVal hwnd&, ByVal uMsg&, ByVal wParam&, ByVal lParam&)
Const GWL_WNDPROC = (-4)
Dim lppwp& '(Long) Pointer to Previous Window Procedure
Function WindowProc&(ByVal hwnd&, ByVal uMsg&, ByVal wParam&, ByVal lParam&)
If uMsg = &H7B& Then uMsg = 0 'Disable WM_CONTEXTMENU
WindowProc = CallWindowProc(lppwp, hwnd, uMsg, wParam, lParam)
End Function
Sub SetContextMenu(Txt As TextBox, bEnable As Boolean)
If bEnable Then
If lppwp Then SetWindowLong Txt.hwnd, GWL_WNDPROC, lppwp
Else
Dim Ret As Long
Ret = SetWindowLong(Txt.hwnd, GWL_WNDPROC, AddressOf WindowProc)
If lppwp = 0 Then lppwp = Ret
End If
End Sub
___
And put the following code in your form. (containing the textbox Text1)
___
Private Sub Form_Load()
SetContextMenu Text1, False
End Sub
___
Test the program.
You can disable the menu on more than one textboxes by calling the SetContextMenu procedure with each textbox.
You can also enable the context menu later by calling this procedure again with bEnable parameter set to True.