DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Disabling right click context menu

  1. #1
    Join Date
    Apr 2006
    Posts
    2

    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)
    Last edited by CFPSoft; 05-11-2006 at 06:20 AM.

  2. #2
    Join Date
    Apr 2006
    Posts
    2
    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

Similar Threads

  1. "Graphical" C# Context menu
    By TabDev in forum .NET
    Replies: 0
    Last Post: 07-27-2005, 07:42 AM
  2. Context Menu Question
    By yigal in forum .NET
    Replies: 1
    Last Post: 07-05-2005, 04:02 PM
  3. Another context menu problem
    By JetserKing in forum VB Classic
    Replies: 0
    Last Post: 02-15-2005, 03:12 PM
  4. Context menu manipulation
    By nnch97 in forum .NET
    Replies: 8
    Last Post: 07-02-2002, 02:09 PM
  5. Add item to floppy drive context menu
    By David Quick in forum VB Classic
    Replies: 0
    Last Post: 04-05-2001, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center