3

I am maintaining an application with a VB6 form that contains a ComponentOne VSFlexGrid 7.0. We have a custom context menu that allows users to perform some specialized copy-and-paste operations. Recently, we have encountered the following issue:

  1. Highlight some text in one of the cells.
  2. Right-click in the cell, with the text still highlighted.
  3. Select one of the context menu options.
  4. The requested context menu operation occurs.
  5. Another context menu similar to the one shown here, with options such as "Right to left reading order", "Open IME", and "Reconversion", is displayed.

How do I make this second context menu go away? I have tried the method that the Microsoft Knowledge Base describes with no luck so far. My WindowProc function is below:

Function WindowProc(ByVal hw As Long, _
                    ByVal uMsg As Long, _
                    ByVal wParam As Long, _
                    ByVal lParam As Long) As Long

    Select Case uMsg
        Case WM_RBUTTONUP
            frmMain.PopupMenu frmMain.mnuPopUp
        Case Else
            WindowProc = CallWindowProc(lpPrevWndProc, hw, _
                                       uMsg, wParam, lParam)
    End Select
End Function

After the copy operation happens, the uMsg values that I see are 15 (WM_PAINT) and 32 (WM_SETCURSOR). I have also noticed that a form-level MouseUp event fires when I have not highlighted text in the cell, but it does not fire when I have highlighted text in the cell.

Could someone with deeper knowledge of VB6 and/or ComponentOne please give me more details about what sequence of events takes place, and how to keep this extra context menu from showing up?

Deanna
  • 23,876
  • 7
  • 71
  • 156
David
  • 1,187
  • 1
  • 10
  • 22
  • 1
    Do you have `BeforeMouseDown` event on the grid? Try setting `Cancel = True` if right clicking. – wqw Aug 25 '11 at 08:35
  • @wqw: Yes, setting Cancel = True does hide the extra context menu. BeforeMouseDown seems like a very early time to do it, though. Would it still work for an event that would fire later, like MouseDown or MouseUp? – David Aug 25 '11 at 15:52
  • I think MouseDown/Up will not fire, but there is no way to cancel `WM_RBUTTONUP` your menu is hooked on. `WM_CONTEXTMENU` would be a more civilized way to do it, but it's implemented by `DefWindowProc` and there is no requirement for a custom control to call it so your grid might not support it -- you have to test it. – wqw Aug 26 '11 at 10:44
  • @wqw: Please make your comments an answer. I think I'll accept it. I still need to hear back from the developer who is working on this bug. He is in another office, and I asked this question on behalf of him. – David Aug 30 '11 at 13:03

2 Answers2

2

You should be handling WM_CONTEXTMENU to show the context menu instead of WM_RBUTTONUP (as it's not just right click that can trigger it) .

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • +1. I think that does start to point us in the right direction. Have you seen the extra context menu that I mentioned in the original post? – David Aug 25 '11 at 12:59
  • No, I haven't used your code, but that message is the one that triggers the real context menu. If you override that than the real one shouldn't be shown at all. – Deanna Aug 25 '11 at 14:26
1

In BeforeMouseDown event try setting Cancel = True if user is right clicking.

wqw
  • 11,771
  • 1
  • 33
  • 41