码迷,mamicode.com
首页 > 其他好文 > 详细

SysTray

时间:2014-12-18 16:34:43      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   ar   io   color   os   sp   for   

  1 //SysTray.cpp
  2 
  3 
  4 #include "vcf/ApplicationKit/ApplicationKit.h"
  5 #include "vcf/ApplicationKit/SystemTray.h"
  6 #include "vcf/ApplicationKit/DefaultMenuItem.h"
  7 
  8 /**
  9 This is a simple example that demonstrates how to use the SystemTray component
 10 */
 11 
 12 using namespace VCF;
 13 
 14 
 15 
 16 class SysTrayWindow : public Window {
 17 public:
 18     SysTrayWindow() {
 19         setCaption( "SysTray" );
 20 
 21         /**
 22         Create a new system tray. Passing a pointer to the
 23         "owner" (in this case the window itself) will automatically
 24         cause the new child component, the system tray, to be added
 25         to it‘s owner. When the owner is destroy, so will any children
 26         of the owner.
 27         */
 28         SystemTray* tray = new SystemTray(this);
 29 
 30         /**
 31         Make the tray icon area visible
 32         */
 33         tray->showInTray();
 34 
 35 
 36         /**
 37         Create a new image on the fly, and add it to the tray
 38         */
 39         Image* img = GraphicsToolkit::createImage( 32, 32 );
 40         img->beginDrawing();
 41         GraphicsContext* gc = img->getImageContext();
 42         gc->rectangle( 0, 0, 32, 32 );
 43         gc->setColor( Color::getColor( "red" ) );
 44         gc->fillPath();
 45 
 46         gc->circle( 16,16, 5 );
 47         gc->circle( 10,10, 5 );
 48         gc->circle( 20,15, 5 );
 49 
 50         gc->setColor( Color::getColor( "blue" ) );
 51         gc->fillPath();
 52 
 53 
 54 
 55         img->finishedDrawing();
 56         
 57         /**
 58         Make the image transparent
 59         */
 60 
 61         img->setIsTransparent( true );
 62         /**
 63         Sets the transparency color
 64         */
 65         img->setTransparencyColor( Color::getColor( "red" ) );
 66 
 67         /**
 68         Set the image for the tray‘s icon.
 69         */
 70         tray->setIconImage( img );
 71 
 72 
 73         /**
 74         We are done with the image so delete it!
 75         */
 76         delete img;
 77 
 78         /**
 79         Set the tooltip popup for the system tray icon
 80         */
 81         tray->setTooltipText( "Hello There!" );
 82         
 83 
 84         
 85 
 86         /**
 87         Create a popup menu with three items and attach event 
 88         handlers to them
 89         */
 90 
 91         PopupMenu* pm = new PopupMenu(this);
 92         MenuItem* root = pm->getRootMenuItem(); // new DefaultMenuItem( "root", NULL, pm );
 93 
 94         DefaultMenuItem* hello = new DefaultMenuItem( "Hello!", root, pm );
 95         hello->MenuItemClicked += new ClassProcedure1<Event*,SysTrayWindow>(this,&SysTrayWindow::onHello,"SysTrayWindow::onHello");
 96 
 97         DefaultMenuItem* about = new DefaultMenuItem( "About...", root, pm );
 98         about->MenuItemClicked += new ClassProcedure1<Event*,SysTrayWindow>(this,&SysTrayWindow::onAbout,"SysTrayWindow::onAbout");
 99 
100         DefaultMenuItem* quit = new DefaultMenuItem( "Quit", root, pm );
101         quit->MenuItemClicked += new ClassProcedure1<Event*,SysTrayWindow>(this,&SysTrayWindow::onQuit,"SysTrayWindow::onQuit");
102         
103         /**
104         Set the tray icon‘s popup menu
105         */
106         tray->setPopupMenu( pm );
107     }
108 
109     virtual ~SysTrayWindow(){};
110 
111     void onHello( Event* e ) {
112         Dialog::showMessage( "Hello There!" );
113     }
114 
115     void onQuit( Event* e ) {
116         close();
117     }
118 
119     void onAbout( Event* e ) {
120         Dialog::showMessage( "Simple application that demonstrates\nhow to use the system tray." );
121     }
122 
123 };
124 
125 
126 
127 
128 class SysTrayApplication : public Application {
129 public:
130 
131     SysTrayApplication( int argc, char** argv ) : Application(argc, argv) {
132 
133     }
134 
135     virtual bool initRunningApplication(){
136         bool result = Application::initRunningApplication();
137         
138         Window* mainWindow = new SysTrayWindow();
139         setMainWindow(mainWindow);
140         mainWindow->setBounds( &Rect( 100.0, 100.0, 500.0, 500.0 ) );
141         mainWindow->show();
142         
143         return result;
144     }
145 
146 };
147 
148 
149 int main(int argc, char *argv[])
150 {
151     Application* app = new SysTrayApplication( argc, argv );
152 
153     Application::main();
154     
155     return 0;
156 }

 

SysTray

标签:des   style   blog   ar   io   color   os   sp   for   

原文地址:http://www.cnblogs.com/elitiwin/p/4171811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!