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.
I am using a Grid control, that is populated at runtime with AreaName, In that GridControl's MouseUp Event, I
Const MF_CHECKED = &H8&
Const MF_APPEND = &H100&
Const TPM_LEFTALIGN = &H0&
Const MF_DISABLED = &H2&
Const MF_GRAYED = &H1&
Const MF_SEPARATOR = &H800&
Const MF_STRING = &H0&
Private Type POINTAPI
X As Long
Y As Long
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal 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
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
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.
Just in the Above code I added the Equipment Names in the Menu, If the User Right Click any
Private Sub JanfpSpr_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As 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
JanfpSpr.GetText 4, JanfpSpr.ActiveRow, JanCritTyp
JanfpSpr.GetText 1, JanfpSpr.ActiveRow, CurSprVal
JanfpSpr.GetText 3, JanfpSpr.ActiveRow, DtVal
ShtType = Mid(CurSprVal, Len(CurSprVal) - 4, Len(CurSprVal))
CurSprVal = Mid(CurSprVal, 1, Len(CurSprVal) - 9)
If JanCritTyp = "Area" Then
SQL = "select * from EquipMaster where ArName='" & Mid(CurSprVal, 7, Len(CurSprVal)) & "' And Nextti Between #" & DtVal & "# And #" & DtVal & "# And ShtTp='" & ShtType & "' order by ENo"
If rstSi.State = 1 Then rstSi.Close
rstSi.Open SQL, cnnNew, adOpenStatic, adLockReadOnly, adCmdText
mnuLstSubItms(0).Caption = Mid(CurSprVal, 7, Len(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
mnuLstEqp.Enabled = True
ElseIf JanCritTyp = "Equipment" Then
mnuLstEqp.Enabled = False
' End If
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()
What happens for this code is, The Popup menu is Show, but as soon as this Popup Menu is shown
Private Sub Form_Load()
hMenu = CreatePopupMenu()
AppendMenu hMenu, MF_STRING, ByVal 0&, "&Update"
AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
AppendMenu hMenu, MF_STRING, ByVal 0&, "&Delete"
AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
AppendMenu hMenu, MF_STRING, ByVal 0&, "&Report"
Private Sub mnuLstSubItms_Click(Index As Integer)
Dim pt As POINTAPI
TrackPopupMenu hMenu, TPM_LEFTALIGN, pt.X, pt.Y, 0, Me.hwnd, ByVal 0&
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.
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."
Last Post: 07-02-2002, 03:09 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center