Disabling right click context menu
I have some code which fires up a custom context menu on right-clicking a true db grid (code included at end of post). However, once I have selected an option on the custom menu, the windows default context menu (cut/copy/paste, etc) displays.
Anyone got any ideas how to prevent this? (its the standard windows right click menu I am trying to prevent from popping up. I am sure there must be an api to do this but can't find one. I don't think my use of a second custom menu is relevant)
[510 byte] By [
CFPSoft] at [2007-11-11 8:34:12]

# 1 Re: Disabling right click context menu
Thought I would update any who have looked at this as I have not one but two answers (provided by Ark at Experts Exchange). Both do the job though the first one is far simpler and uses less lines of code. I am including both here in case the first doesn't work in certain circumstances:
Please note for both solutions the popup code must go in the control's mouse DOWN event not the mouse UP as the windows popup is handled outside of VB before the mouseup event fires.
Example 1
lngReturn= SendMessage(tdbgBoundTemp.hwnd, 1399, 1, ByVal 0&)
'custom popup code goes here
lngReturn= SendMessage(tdbgBoundTemp.hwnd, 1399, 0, ByVal 0&)
Example 2
This example disables the control (text1) and prevents from looking disabled by calling the LockWindowUpdate API. Then re-enables and unlocks updates after the custom popup code has fired
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hwndLock As Long) As Long
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