Uses "UI"
Uses "Console"
' -- Menu IDs
Begin ControlID
%menu_Item1
%menu_Item2
%menu_SubItem1
%menu_SubItem2
End ControlID
Declare Function TrackPopupMenu Lib "USER32.DLL" Alias "TrackPopupMenu" (ByVal hMenu As DWord, ByVal uFlags As DWord, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hWnd As DWord, lprc As RECT) As Long
' ----------------------------------------------
' Create main dialog
' ----------------------------------------------
Function TBMain()
Dim hDlg As DWord
Dialog New Pixels, 0, "Context menu demo",-1,-1, 320, 240, %WS_POPUP | %WS_VISIBLE | %WS_CLIPCHILDREN | %WS_CAPTION | %WS_SYSMENU | %WS_MINIMIZEBOX To hDlg
Dialog Show Modal hDlg Call cbDialog
End Function
' ----------------------------------------------
' Handling dialog events
' ----------------------------------------------
CallBack Function cbDialog() As Long
Local cr As CHARRANGE
Local pt As POINTAPI
Local lResult As DWord
Static hMenu As Long
Static hPopup1 As Long
Static hPopup2 As Long
Select Case Callback_Message
Case %WM_INITDIALOG
' -- First create a top-level menu:
MENU New Bar To hMenu
' -- Add a top-level menu item with a popup menu:
MENU New Popup To hPopup1
MENU Add Popup, hMenu, "Right click menu", hPopup1, %MF_ENABLED
MENU Add String, hPopup1, "Item 1", %menu_Item1, %MF_ENABLED
MENU Add String, hPopup1, "Item 2", %menu_Item2, %MF_ENABLED
MENU Add String, hPopup1, "-", 0, 0
' -- Now we can add another item to the menu that will bring up a sub-menu. First we obtain a new popup menu handle to distinuish it from the first popup menu:
MENU New Popup To hPopup2
' -- Now add a new menu item to the first menu. This item will bring up the sub-menu when selected:
MENU Add Popup, hPopup1, "More items", hPopup2, %MF_ENABLED
' -- Now we will define the sub menu:
MENU Add String, hPopup2, "SubItem 1", %menu_SubItem1, %MF_ENABLED
MENU Add String, hPopup2, "SubItem 2", %menu_SubItem2, %MF_ENABLED
Case %WM_RBUTTONDOWN
' -- Get position passed by event
pt.x = LOWRD(Callback_LParam)
pt.y = HIWRD(Callback_LParam)
' -- Convert local window position to screen position
Win_ClientToScreen(Callback_Handle, pt)
' -- Show and Handle menu.
' -- Important: use %TPM_RETURNCMD otherwise the choosed command will not be returned
lResult = TrackPopupMenu(hPopup1, %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON Or %TPM_RETURNCMD, pt.x, pt.y, 0, Callback_Handle, ByVal %NULL)
End Select
End Function
If you need a context menu in shell, I think you need to dive into COM and implement class satisfying IContextMenu interface.
Bookmarks