Page 1 of 1

Systray Popup Menu

Posted: Fri Sep 07, 2001 9:18 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Code updated for 5.20+

Code: Select all

; Place a tray icon
; left click opens a popup menu
; right click closes the program
; (c) 2001 - Franco's template - absolutely freeware

Procedure.l Screen_Width ()
  ProcedureReturn GetSystemMetrics_(#SM_CXSCREEN)
EndProcedure

Procedure.l Screen_Height ()
  ProcedureReturn GetSystemMetrics_ (#SM_CYSCREEN)
EndProcedure

Structure pt
  x.l
  y.l
EndStructure
Cursor.pt

If CreatePopupMenu(0)
  MenuItem(1, "Cut")
  MenuItem(2, "Copy")
  MenuItem(3, "Paste")
  MenuBar()
  OpenSubMenu("Options")
  MenuItem(4, "Window...")
  MenuItem(5, "Gadget...")
  CloseSubMenu()
  MenuBar()
  MenuItem( 6, "About")
EndIf
;open a window (needed...) but put it outside the desktop
If OpenWindow(0, Screen_Width (), Screen_Height (), 0, 0, "(c) 2001 - Franco's template - absolutely freeware", #PB_Window_SystemMenu)
  AddSysTrayIcon(1, WindowID(0), LoadIcon_(0, #IDI_WINLOGO))
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_SysTray
      If EventType() = #PB_EventType_LeftClick
        ResizeWindow(0, Screen_Width (), Screen_Height (), #PB_Ignore, #PB_Ignore) ;if somebody resizes the desktop
        GetCursorPos_(Cursor)
        xPos=Cursor\x
        yPos=Cursor\y
        
        DisplayPopupMenu(0, WindowID(0), xPos, yPos)
        
        Repeat
          Select WaitWindowEvent()
            Case #PB_Event_Menu
              Select EventMenu()
                Case 1 ; Cut
                  MessageRequester("(c) 2001 - Franco's template", "Cut", 0)
                  ExitMenu = 1
                Case 2 ; Copy
                  MessageRequester("(c) 2001 - Franco's template", "Copy", 0)
                  ExitMenu = 1
                Case 3 ; Paste
                  MessageRequester("(c) 2001 - Franco's template", "Paste", 0)
                  ExitMenu = 1
                Case 4 ; Options
                  MessageRequester("(c) 2001 - Franco's template", "Options", 0)
                  ExitMenu = 1
                Case 5 ; Gadget
                  MessageRequester("(c) 2001 - Franco's template", "Gadget", 0)
                  ExitMenu = 1
                Case 6 ; About
                  MessageRequester("(c) 2001 - Franco's template", "Absolutely Freeware!", 0)
                  ExitMenu = 1
              EndSelect
            Case #PB_Event_CloseWindow
              ExitMenu = 1
          EndSelect
          
        Until ExitMenu = 1
        Quit = 0

      EndIf
    EndIf
    
  Until Event = #PB_Event_CloseWindow
  
EndIf
End
;---------------------------------------------------------
Have a nice day...
Franco

Posted: Sat Sep 08, 2001 2:58 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Great example Franco

only one thing: why make the window visible but out of the screen?
i think the is some way to work around this making a hidden window


Regards,
Ricardo

Posted: Mon Sep 17, 2001 5:36 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Yes Ricardo, after creating the window I forgot this command:

showwindow_(windowid(),0)

I like to put invisible windows outside the desktop, but you have right it is not necessary.



Have a nice day...
Franco