Here my code to display the menu:

Private Sub Text5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
PopupMenu t5menu
End If
End Sub

But my problem is the default popup menus such as undo, copy, cut etc. keeps in taking place instead of the menus i set up..
Help me pls..

Dani AI

Generated

Short answer: the standard edit control is showing its own context menu after VB’s MouseDown runs. Calling PopupMenu from MouseDown (as did) does not cancel the edit control’s built‑in handling — Windows sends a WM_CONTEXTMENU (or the control handles a right‑button message) and the native menu appears unless you stop that message.

What works reliably is intercepting the control’s window messages (subclassing) and suppressing WM_CONTEXTMENU (and sometimes WM_RBUTTONUP). pointed at both subclassing and some non‑subclass tricks; the latter (timers, overlays) can be brittle and fail in edge cases, so subclassing is the usual, robust approach.

High‑level safe approach (no code here): replace the textbox window procedure with your own in a standard module, check incoming messages for WM_CONTEXTMENU (and/or right‑button messages) and return without forwarding them to the original procedue; forward every other message. Always restore the original window procedure when the control or form is destroyed, and wrap unhooking in error handlers. Test this behavior in a compiled EXE — doing subclassing in the IDE can crash the IDE if something goes wrong.

See the Windows documentation for the message and the window‑proc APIs for exact names and semantics: WM_CONTEXTMENU and SetWindowLongPtr / SetWindowLong. Subclassing is powerful but must be done carefully; if avoiding it is a firm requirement, consider a small custom usercontrol (your own edit wrapper) so you control the right‑click behavior without touching native wndprocs.

Recommended Answers

All 2 Replies

Not a simple solution as you have to subclass the textbox. Please see this example...

http://vbnet.mvps.org/index.html?code/subclass/contextmenu.htm

or this that says you don't need to subclass...

http://www.devx.com/vb2themax/Tip/18376

this one uses subclassing in conjunction with a dll...

http://www.devx.com/vb2themax/Tip/18413

and not so sure about this one as it uses a timer and the OP says you cannot completly disable the popup...

http://www.a1vbcode.com/snippet-4474.asp

as this one tries to also get around it without using subclassing or the API...

http://www.a1vbcode.com/snippet-3848.asp

while this one does subclass but has a project you can download...

http://www.thescarms.com/VBasic/SubClassCtrls.aspx

same here...

http://www.vb-helper.com/howto_remove_context_menu.html

and this is the search I used to find these examples...

http://search.yahoo.com/search?p=vb6+popup+menu+textbox&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-701

Good Luck

Thanks for the help....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.