Page 1 of 1

[PB4.40b6] SysTray and Events

Posted: Wed Nov 11, 2009 8:31 pm
by jamirokwai
Dear Fred,

I was playing around with the SysTray-Thing on Mac OS X. Looks really promising. However, I fell into a little trap...

The following code opens a window, sets up the SysTrayIcon and a Menu, and waits for the user to click. There are two options in the Menu. Works as expected.

If you bring Finder to front and click again on the SysTrayIcon, the Menu appears. But when selecting a line with left mouse button, the #PB_Event_Menu-part won't be executed. As you can see, I added BringToFront_ and SetActiveWindow, which didn't do the trick :(

Any ideas?

Code: Select all

OpenWindow(0,50,50,50,50,"systraytest")
 CreatePopupMenu(0)
  MenuItem(1,"Test")
  MenuItem(2,"Quit")
 CreateImage(0,40,16,32) 
 StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AlphaChannel|#PB_2DDrawing_Transparent)
  Box(0, 0, 40, 16, RGBA(0,0,0,0))
  DrawText(1,1,"TEST",RGBA(0,0,0,255))
 StopDrawing()
 
 AddSysTrayIcon (0, WindowID(0), ImageID(0))
 
Repeat
 Select WaitWindowEvent()
  Case #PB_Event_SysTray
   Select EventType()
    Case #PB_EventType_LeftClick
; this won't help
;      BringToFront_(WindowID(0))
;      SetActiveWindow(0)
     DisplayPopupMenu(0, WindowID(0))
   EndSelect
   
   ; this won't be executed, when the program is set to background
  Case #PB_Event_Menu
   Select EventMenu()
    Case 1 : MessageRequester("!", "works")
    Case 2 : Exit = 1
  EndSelect
 EndSelect
Until Exit = 1
EDIT: I think, It is the same question (or answer) as in http://www.purebasic.fr/english/viewtop ... 24&t=39861

Re: [PB4.40b6] SysTray and Events

Posted: Tue Feb 09, 2010 6:04 pm
by Niffo
+1

Re: [PB4.40b6] SysTray and Events

Posted: Tue Feb 09, 2010 10:03 pm
by WilliamL
It appears that Toolbars also work if you use ToolBarImageButton.