CustomTray


In the previous chapter I talked about the Windows tray, and I promised an example after events were covered. This Tray subclass is instantiated in the Open event of the RSS class:

Dim myTrayItem as CustomTray myTrayItem = New CustomTray Me.AddTrayItem( myTrayItem ) 


To work with the tray, you need to subclass TrayItem. The Action event controls what happens when the user clicks the icon as it appears on the tray. This class doesn't really perform anything useful, and it is based on the example used in REALbasic's documentation, but it should be enough to show you how it works. The Action event gets passed an Integer that indicates what kind of action has taken placewhether the left or right mouse button was clicked, or if it was double-clicked. In this example, the main application Window will get maximized if the TrayItem is clicked with the left mouse button. If the right mouse button is clicked, a MenuItem pops up and provides an About option and an Exit option. Finally, if the TrayItem is double-clicked, the application becomes invisible if it is currently visible. If it is currently invisible, it will become visible.

[View full width]

Sub CustomTray.Action(cause as Integer)Handles Event If cause = TrayItem.LeftMouseButton Then Window1.Maximize ElseIf cause = TrayItem.RightMouseButton Then Dim mnu as New MenuItem mnu.Append( new MenuItem( "&About" ) ) mnu.Append( new MenuItem( MenuItem.TextSeparator ) ) mnu.Append( new MenuItem( "E&xit" ) ) Dim results as MenuItem results = mnu.PopUp If results <> Nil Then Select Case results.Text Case "E&xit" Quit Case "&About" MsgBox "RSSReader from REALbasic Cross-platform Application Development" End Select End If Elseif cause = TrayItem.DoubleClick Then If Window1.Visible Then Window1.Visible = False Else Window1.Visible = True End if End If End Sub





REALbasic Cross-Platform Application Development
REALbasic Cross-Platform Application Development
ISBN: 0672328135
EAN: 2147483647
Year: 2004
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net