There are two ways to do this. Either subclass the WM_INITMENUPOPUP message and consume it, or use the following instructions (from MSDN):
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Add a TextBox control to Form1.
Choose Menu Editor from the Tools menu and create a menu named mnuPopUp on Form1. Deselect the Visible CheckBox and add items such as the following:
File
New
Open
Add the following code to the code window of Form1:
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hwndLock As Long) As Long
Private Sub mnuOne_Click()
Text1.Text = "Menu One was clicked"
End Sub
Private Sub mnuTwo_Click()
Text1.Text = "Menu two was clicked"
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If Button = vbRightButton Then
' Avoid the 'disabled' gray text by locking updates
LockWindowUpdate Text1.hWnd
' A disabled TextBox will not display a context menu
Text1.Enabled = False
' Give the previous line time to complete
DoEvents
' Display our own context menu
PopupMenu mnuPopup
' Enable the control again
Text1.Enabled = True
' Unlock updates
LockWindowUpdate 0&
End If
End Sub
Save and run the project.
Alternate-mouse click on Text1. Only the custom menu is displayed. The standard editing menu is not shown.
Enter your message below
Sign in or Join us (it's free).