@PB
Oh dear, we seem to be going around in circles...
My need is for a standard menu, attached to a menu bar, to close when the mouse pointer goes away from the menu.
Your original solution addresses the same need but with a popup menu.
It does not work if there is a gadget under the popup menu; as is almost inevitably the case .
Code: Select all
Procedure WindowCallback(hwnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_ENTERIDLE
GetCursorPos_(cpt.POINT)
If WindowFromPoint_(PeekQ(cpt))=hwnd
EndMenu_()
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,320,240,"Right-click!",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,20,20,200,200,"Test")
CreatePopupMenu(0)
MenuItem(1,"Cut")
MenuItem(2,"Copy")
MenuItem(3,"Paste")
MenuBar()
OpenSubMenu("Options")
MenuItem(4,"Window...")
MenuItem(5,"Gadget...")
CloseSubMenu()
MenuBar()
MenuItem(6,"Quit")
SetWindowCallback(@WindowCallback())
Repeat
EventID = WaitWindowEvent()
If EventID = #WM_RBUTTONDOWN
DisplayPopupMenu(0,WindowID(0))
EndIf
Until EventID = #PB_Event_CloseWindow
Neither does it work with a standard menu attached to a menu bar:
Code: Select all
Procedure WindowCallback(hwnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_ENTERIDLE
GetCursorPos_(cpt.POINT)
If WindowFromPoint_(PeekQ(cpt))=hwnd
EndMenu_()
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,320,260,"Select menu then move mouse right",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,20,20,200,200,"Hello")
CreateMenu(0,WindowID(0))
MenuTitle("Things")
MenuItem(1,"Cut")
MenuItem(2,"Copy")
MenuItem(3,"Paste")
MenuBar()
OpenSubMenu("Options")
MenuItem(4,"Window...")
MenuItem(5,"Gadget...")
CloseSubMenu()
MenuBar()
MenuItem(6,"Quit")
SetWindowCallback(@WindowCallback())
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
In this case the callback is being triggered repeatedly and the menu cannot deploy.
@Shardik
Almost perfect....
The only remaining difficulty is that if a user exits with the conventional left mouse button it takes two attempts to get the menu to drop down again.