隨筆 - 119  文章 - 3173  trackbacks - 0
          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          交友莫獨酒,茅臺西鳳游。
          口干古井貢,心徜洋河流。
          稱多情杜康,趟無量雙溝。
          贊中華巍巍,無此不銷愁。

          常用鏈接

          留言簿(68)

          隨筆分類(136)

          隨筆檔案(122)

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 526712
          • 排名 - 92

          最新評論

          看到有位朋友在偶“為RCP程序增加關閉提示和關閉到系統托盤”的文章里面的留言,忍不住把自己以前N老的一篇帖子扒出來了。
          此文可能是當初最早最完善的SWT實現任務欄圖標,帶菜單、帶ToolTip的完整的例子。
          期間還有CSDN會員GhostValley;pdvv的指教。


          ?1?import?org.eclipse.swt.SWT;
          ?2?import?org.eclipse.swt.events.ShellListener;
          ?3?import?org.eclipse.swt.graphics.Image;
          ?4?import?org.eclipse.swt.internal.win32.OS;
          ?5?import?org.eclipse.swt.widgets.Display;
          ?6?import?org.eclipse.swt.widgets.Event;
          ?7?import?org.eclipse.swt.widgets.Listener;
          ?8?import?org.eclipse.swt.widgets.Menu;
          ?9?import?org.eclipse.swt.widgets.MenuItem;
          10?import?org.eclipse.swt.widgets.Shell;
          11?import?org.eclipse.swt.widgets.Tray;
          12?import?org.eclipse.swt.widgets.TrayItem;
          13?
          14?public?class?MyTray?{
          15?????public?static?void?main(String[]?args)?{
          16?????????Display?display?=?new?Display();
          17?????????Shell?shell?=?new?Shell(display);
          18?????????//?下面兩句的效果是:在任務欄不顯示
          19?????????//?感謝CSDN會員:GhostValley(鬼谷)
          20?????????final?int?hWnd?=?shell.handle;
          21?????????OS.SetWindowLong(hWnd,?OS.GWL_EXSTYLE,?OS.WS_EX_CAPTIONOKBTN);
          22?????????Image?image?=?new?Image(display,?16,?16);
          23?????????final?Tray?tray?=?display.getSystemTray();
          24?????????if?(tray?==?null)?{
          25?????????????System.out.println("The?system?tray?is?not?available");
          26?????????}?else?{
          27?????????????final?TrayItem?item?=?new?TrayItem(tray,?SWT.NONE);
          28?????????????item.setToolTipText("SWT?TrayItem");
          29?????????????item.addListener(SWT.Show,?new?Listener()?{
          30?????????????????public?void?handleEvent(Event?event)?{
          31?????????????????????System.out.println("show");
          32?????????????????}
          33?????????????});
          34?????????????item.addListener(SWT.Hide,?new?Listener()?{
          35?????????????????public?void?handleEvent(Event?event)?{
          36?????????????????????System.out.println("hide");
          37?????????????????}
          38?????????????});
          39?????????????item.addListener(SWT.Selection,?new?Listener()?{
          40?????????????????public?void?handleEvent(Event?event)?{
          41?????????????????????System.out.println("selection");
          42?????????????????}
          43?????????????});
          44?????????????item.addListener(SWT.DefaultSelection,?new?Listener()?{
          45?????????????????public?void?handleEvent(Event?event)?{
          46?????????????????????System.out.println("default?selection");
          47?????????????????????//?show?main
          48?????????????????????Shell?s?=?event.display.getShells()[0];
          49?????????????????????s.setVisible(true);
          50?????????????????????s.setMinimized(false);
          51?????????????????}
          52?????????????});
          53?????????????final?Menu?menu?=?new?Menu(shell,?SWT.POP_UP);
          54?????????????for?(int?i?=?0;?i?<?8;?i++)?{
          55?????????????????MenuItem?mi?=?new?MenuItem(menu,?SWT.PUSH);
          56?????????????????mi.setText("Item"?+?i);
          57?????????????}
          58?????????????item.addListener(SWT.MenuDetect,?new?Listener()?{
          59?????????????????public?void?handleEvent(Event?event)?{
          60?????????????????????menu.setVisible(true);
          61?????????????????}
          62?????????????});
          63?????????????item.setImage(image);
          64?????????}
          65?????????shell.addShellListener(new?ShellListener()?{
          66?????????????public?void?shellDeactivated(org.eclipse.swt.events.ShellEvent?e)?{
          67?????????????}
          68?
          69?????????????public?void?shellActivated(org.eclipse.swt.events.ShellEvent?e)?{
          70?????????????}
          71?
          72?????????????public?void?shellClosed(org.eclipse.swt.events.ShellEvent?e)?{
          73?????????????}
          74?
          75?????????????public?void?shellDeiconified(org.eclipse.swt.events.ShellEvent?e)?{
          76?????????????}
          77?
          78?????????????public?void?shellIconified(org.eclipse.swt.events.ShellEvent?e)?{
          79?????????????????//?最小化時不顯示在任務欄
          80?????????????????//?感謝CSDN會員:pdvv(我愛花貓)
          81?????????????????((Shell)?e.getSource()).setVisible(false);
          82?????????????}
          83?????????});
          84?????????shell.setBounds(50,?50,?300,?200);
          85?????????shell.open();
          86?????????while?(!shell.isDisposed())?{
          87?????????????if?(!display.readAndDispatch())
          88?????????????????display.sleep();
          89?????????}
          90?????????image.dispose();
          91?????????display.dispose();
          92?????}
          93?}
          posted on 2006-12-26 15:47 交口稱贊 閱讀(4719) 評論(6)  編輯  收藏 所屬分類: Eclipse RCP SWTjava相關

          FeedBack:
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-26 16:50 BeanSoft
          哈..沒想到當時找到的資料原來作者就是博主啊, 不過還有人轉貼不留來源的.

          看看偶當時做插件之前找的資料:

          計劃開發一個 Eclipse/Netbeans 最小化到托盤的插件
          http://www.aygfsteel.com/beansoft/archive/2006/12/14/87654.aspx  回復  更多評論
            
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-26 17:36 交口稱贊
          呵呵,當年的csdn號。。。。。。。
          我還提交的CSDN的F/Q里面了。
            回復  更多評論
            
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-27 21:46 wypicc
          我會經常來學習地
          呵呵  回復  更多評論
            
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-29 21:36 jrobot[匿名]
          雖然偶不懂rcp但是偶知道 swt早就支持系統托盤了

          不支持不能跨平臺的代碼- -  回復  更多評論
            
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-30 00:49 交口稱贊
          ..........................................
          這個例子跟RCP有關嗎?
          本來就是純SWT的
          拜托看仔細
          而且這個例子也是“很早”就寫出來了

          拜托看看CSDN里面的原帖
          我只是因為跟一個朋友討論RCP怎么實現托盤才扒出來的  回復  更多評論
            
          # re: 強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和ToolTip 2006-12-30 00:52 交口稱贊
          其實OS類現在看來是不必要的
          那時候水平有限
          瞎貓碰死老鼠,亂試

          有時間我測試下去了OS的相關東西看能不能跨平臺
          而且現在java6本身就是支持系統托盤  回復  更多評論
            
          主站蜘蛛池模板: 夏津县| 安义县| 淮滨县| 吴江市| 深州市| 襄城县| 微博| 四川省| 甘泉县| 吉安县| 德安县| 加查县| 拜城县| 高平市| 西和县| 治多县| 惠水县| 乌苏市| 江门市| 武邑县| 桂林市| 含山县| 玉田县| 新龙县| 遵化市| 平顶山市| 清徐县| 昂仁县| 沿河| 蕲春县| 渭南市| 辽阳市| 栖霞市| 双牌县| 崇左市| 高陵县| 延边| 当雄县| 阿图什市| 栖霞市| 廉江市|