5.62 : BindEvent(#PB_Event_Menu, ...) does not work if ...

Just starting out? Need help? Post your questions and find answers here.
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

5.62 : BindEvent(#PB_Event_Menu, ...) does not work if ...

Post by Niffo »

Unlike on Windows, BindEvent(#PB_Event_Menu, ...) does not work at least the first time (or can trigger events on other windows) if called after the DisplayPopupMenu() :

Code: Select all


Procedure Callback_Menu_Events()
   Debug "Callback_Menu_Events()"
   UnbindEvent(#PB_Event_Menu, @Callback_Menu_Events(), 0)
EndProcedure

OpenWindow(0, 100, 100, 300, 300, "Menu events test")

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_RightClick
         CreatePopupMenu(0)
         MenuItem(0, "Item 1")
         MenuItem(1, "Item 2")
         MenuItem(2, "Item 3")
         DisplayPopupMenu(0, WindowID(0))
         BindEvent(#PB_Event_Menu, @Callback_Menu_Events(), 0)
         
      Case #PB_Event_CloseWindow
         Break
   EndSelect
ForEver
Niffo
Fred
Administrator
Administrator
Posts: 16681
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 5.62 : BindEvent(#PB_Event_Menu, ...) does not work if .

Post by Fred »

It's not a bug, DisplayPopupMenu() is blocking the event chain, so you need to register BindEvent() before calling it (if it works on Windows, it's luck).
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: 5.62 : BindEvent(#PB_Event_Menu, ...) does not work if .

Post by Niffo »

Thank you, noted. Maybe it should be specified somewhere in the doc ?
Niffo
Post Reply