[Gambas-user] Gambas in background
Benoît Minisini
gambas at ...1...
Wed Apr 21 16:07:30 CEST 2010
> Hi Bill,
>
> Yes, it is.
>
> I have developed a little test app for you that shows this in action.
>
> Module1 is set as the Startup Class, in place of the more normal Form.
> As it's the Startup Class, main() gets run automatically when you start
> the program. First thing it does is instantiate the TrayIcon and give
> it a tool tip so you know it's working.
> Very important is the following Object.Attach line as this ensures your
> module captures the events raised by the TrayIcon.
No need to use Object.Attach(), as there is a syntax for that. Look at the
documentation of the NEW instruction.
> This is normally not
> necessary when you stick a control on a Form, as the Attach is
> automatic. Then we make sure the TrayIcon gets Shown.
>
> After this, we instantiate a dummy form (I couldn't see any way around
> this... Benoit??)
You need a window to create a menu, that's true.
> and then start to define our menus. The top-level
> menu has the dummy form set as its parent (also important that the dummy
> form has been instantiated (using NEW Form)...but it doesn't need to be
>
> [...]
>
> P.S. The full code for Module1 is as follows:
> ' Gambas module file
> PRIVATE MyTrayIcon AS TrayIcon
> PRIVATE MyMenu AS Menu
> PRIVATE MySubMenu1 AS Menu
> PRIVATE MySubMenu2 AS Menu
> PRIVATE MySubMenu3 AS Menu
> PRIVATE MyDummyForm AS Form
>
> PUBLIC SUB main()
>
> MyTrayIcon = NEW TrayIcon
-----------------------------> AS "MyTrayIcon"
> MyTrayIcon.Tooltip = "Hi from Gambas"
> Object.Attach(MyTrayIcon, ME, "MyTrayIcon")
...and you can remove the previous line.
You can do that for all instanciations below.
> MyTrayIcon.Show
>
> MyDummyForm = NEW Form
>
> MyMenu = NEW Menu(MyDummyForm, FALSE)
> MyMenu.Caption = "TrayMenu"
> MyMenu.Tag = "TrayMenu"
> MyMenu.Name = "TrayMenu"
>
> MySubMenu1 = NEW Menu(MyMenu, FALSE)
> MySubMenu1.Caption = "Status"
> MySubMenu1.Tag = "Status"
> MySubMenu1.Name = "mnuStatus"
> Object.Attach(MySubMenu1, ME, "MyMenu1")
>
> MySubMenu2 = NEW Menu(MyMenu, FALSE)
> MySubMenu2.Caption = "Show Main"
> MySubMenu2.Tag = "ShowMain"
> MySubMenu2.Name = "mnuShowMain"
> Object.Attach(MySubMenu2, ME, "MyMenu2")
>
> MySubMenu3 = NEW Menu(MyMenu, FALSE)
> MySubMenu3.Caption = "Exit Program"
> MySubMenu3.Tag = "Exit"
> MySubMenu3.Name = "mnuExit"
> Object.Attach(MySubMenu3, ME, "MyMenu3")
>
> END
>
> PUBLIC SUB MyTrayIcon_Menu()
>
> MyMenu.Popup()
>
> END
>
> PUBLIC SUB MyMenu1_Click()
>
> Message.Info("Your program is: RUNNING")
>
> END
>
> PUBLIC SUB MyMenu2_Click()
>
> FMain.Show
>
> END
>
> PUBLIC SUB MyMenu3_Click()
>
> QUIT
Do not use QUIT in GUI programs. Just close your form.
>
> END
>
Regards,
--
Benoît Minisini
More information about the User
mailing list