How to find RightClick event in SubMenu & creat anothe Menu thru APICode & writ Evnt

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How to find RightClick event in SubMenu & creat anothe Menu thru APICode & writ Evnt

  1. #1
    Join Date
    Jun 2005

    Smile How to find RightClick event in SubMenu & creat anothe Menu thru APICode & writ Evnt

    [COLOR=Sienna]How to Popup a Menu for the Menu created by MenuEditor & populated at runtime, the Popup should be shown when the user right click the Menu.[/COLOR]

    I need to show the PopuMenu for populated Menu, either its created by API as below or by MenuObject. The below
    is the way i created the Menu through API based on the sample of ROB in this Forum.

    The below is the code in the General Declaration Section in the Form.
    PHP Code:
    Const MF_CHECKED = &H8&
    MF_APPEND = &H100&
    MF_DISABLED = &H2&
    MF_GRAYED = &H1&
    MF_SEPARATOR = &H800&
    MF_STRING = &H0&
    As Long
    As Long
    End Type
    Private Declare Function CreatePopupMenu Lib "user32" () As Long
    Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As LongByVal wFlags As LongByVal X As LongByVal Y As LongByVal nReserved As LongByVal hwnd As LongByVal lprc As Any) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As LongByVal bRevert As Long) As Long
    Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As LongByVal wFlags As LongByVal wIDNewItem As LongByVal lpNewItem As Any) As Long
    Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim hMenu 
    As Long

    Private Type MSG
    As Long
    As Long
    As Long
    As Long
    As Long
    End Type 
    I am using a Grid control, that is populated at runtime with AreaName, In that GridControl's MouseUp Event, I
    am loading the Equipment for the Cicked Area is populated and displayed in a Menu and shown to the user. By using
    the below code. It works fine. All Equipments are added to the Menu created by the Menu Editor at runtime.

    PHP Code:
    Private Sub JanfpSpr_MouseUp(Button As IntegerShift As IntegerAs SingleAs Single)
    Dim CurSprVal As Variant
        Dim DtVal 
    As Variant
        Dim oMenu 
    As Menu
        Dim rstSi 
    As New ADODB.Recordset
        Dim ShtType 
    As String
        Dim JanCritTyp 
    As Variant
    If Button vbLeftButton Then
    .GetText 4JanfpSpr.ActiveRowJanCritTyp
    .GetText 1JanfpSpr.ActiveRowCurSprVal
    .GetText 3JanfpSpr.ActiveRowDtVal
    Mid(CurSprValLen(CurSprVal) - 4Len(CurSprVal))
    CurSprVal Mid(CurSprVal1Len(CurSprVal) - 9)
    JanCritTyp "Area" Then
    "select * from EquipMaster where ArName='" Mid(CurSprVal7Len(CurSprVal)) & "' And Nextti Between #" DtVal "# And #" DtVal "# And ShtTp='" ShtType "' order by ENo"
    If rstSi.State 1 Then rstSi.Close
    .Open SQLcnnNewadOpenStaticadLockReadOnlyadCmdText
                    Call UnloadMenuItems
    (0).Caption Mid(CurSprVal7Len(CurSprVal))
    mnuLstSubItms(0).Enabled False
    While Not rstSi.EOF
                        Load mnuLstSubItms
    (mnuLstSubItms.Count 1)
    mnuLstSubItms(mnuLstSubItms.UBound).Caption rstSi.Fields("ENo")
    mnuLstSubItms(mnuLstSubItms.UBound).Enabled True
    .Enabled True
                    Call PopupMenu
    JanCritTyp "Equipment" Then
                   Call UnloadMenuItems
    .Enabled False
                   Call PopupMenu
    End If
    End If
    '    End If
    End Sub 
    Just in the Above code I added the Equipment Names in the Menu, If the User Right Click any
    1 of the Equipment from the Menu then i need to show a Popup Menu with Update,Report etc.
    for this Popup from the Equipment I added the Below Code in Form_Load() and mnuLstSubItms_Click()
    PHP Code:
    Private Sub Form_Load()
    hMenu CreatePopupMenu()
    AppendMenu hMenuMF_STRINGByVal 0&, "&Update"
    AppendMenu hMenuMF_SEPARATORByVal 0&, ByVal 0&
    AppendMenu hMenuMF_STRINGByVal 0&, "&Delete"
    AppendMenu hMenuMF_SEPARATORByVal 0&, ByVal 0&
    AppendMenu hMenuMF_STRINGByVal 0&, "&Report"
    End Sub

    Private Sub mnuLstSubItms_Click(Index As Integer)
    Dim pt As POINTAPI
        GetCursorPos pt
        TrackPopupMenu hMenu
    TPM_LEFTALIGNpt.Xpt.Y0Me.hwndByVal 0&
    End Sub 
    What happens for this code is, The Popup menu is Show, but as soon as this Popup Menu is shown
    the existing PopuMenu disappears, i need both to be visible as we can see in Windows Menus


    How to find which MouseButton is Clicked in the mnuLstSubItms_Click Event.
    How to and where to write the Events for the PopupMenu created through API (for Menu Update,Report)
    How to protect without the Menu disappears, when the user right click the Equipment.

    As (Moderator) Rob said i posted here this issue in the New Thread. Hope any VBForums member
    might have faced the same scenario. Kindly check this and reply me.

    The picture of the Menus on runtime and design time are also attached here for your reference.


  2. #2
    Join Date
    Nov 2003
    Alameda, CA
    Use the MouseUp instead of the Click event to display the menu

    Do you really use the APIs to create a runtime menu? That is not necessary.

    Open the Menu editor (Ctrl+E) in design mode, when your form is shown in the IDE.
    Add a menu (let's call it mnuPopup) and mark it as Invisible (visible = false). Now add to it a a sub menu (let's call it mnuItem) and make it an array (set its Index to 0).

    At run time, use "Load mnuItem(1)" to create another subMenu (as many as you want). Use "Unload mnuItem(1)" to remove it. This is the same tecnique that is used to create controls dynamically.

    At the mose down event, use "me.PopupMenu mnuPopup" to display the menu in the MouseUp event.

    Let me know.

    PS please do not ask questions sending private messages, use the forum so that everyone can take the benefit
    "There are two ways to write error-free programs. Only the third one works."

Similar Threads

  1. Context menu manipulation
    By nnch97 in forum .NET
    Replies: 8
    Last Post: 07-02-2002, 03:09 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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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