Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TrackPopupMenu item selected?

Status
Not open for further replies.

Horrid

Programmer
May 20, 1999
373
I have generated a dynamic menu with Createpopupmenu and TrackPopupMenu. My problem is that I have no idea to now detect when and what menu item is selected. Any suggestions?

Thanks in advance
 
At the moment u want to display the menu, with TrackPopupMenu I guess, you just look at the return value, which is the Index of the menuitem.

So if you want to display a menu on a MouseUp on the Form, you have something like this:

[tt]Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lpPoint As POINTAPI
Dim lReturn As Long

Call GetCursorPos(lpPoint)
lReturn = TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, lpPoint.x, lpPoint.y, 0, Me.hwnd, ByVal 0&)
Select Case lReturn
'here you should compare the ID to the ID's of the Items you've added to the PopupMenu
End Select
End Sub[/tt]
 
Oh, just to clarify the ID part, if you've used AppendMenu to create the PopupMenu, you haven't specified the ID. To retrieve the ID in this case use:

[tt]Declare Function GetMenuItemID Lib "user32" Alias "GetMenuItemID" (ByVal hMenu As Long, ByVal nPos As Long) As Long

· hMenu
Identifies the menu that contains the item whose identifier is to be retrieved.

· nPos
Specifies the zero-based relative position of the menu item whose identifier is to be retrieved.[/tt]

If you've used InsertMenuItem you've already specified which ID you want to use for the MenuItem, so that should work I guess.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top