線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2242
推到 Plurk!
推到 Facebook!

Tray ICon 都做好了 但是剩下最後一個步驟...消除 balloon!!

尚未結案
hedge
一般會員


發表:4
回覆:10
積分:2
註冊:2004-09-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-27 18:33:09 IP:202.39.xxx.xxx 未訂閱
Dear All... 以下是我參考 K. Top 以及透過 google 找到的範例 把它們包裝好的程式.... 這一段程式剛好是我要的...程式跑起來 縮小時跑到 右下角跟 Msn 擠在一起 當 timer 觸發時 會跑出一個汽球 balloon , 一陣子汽球消失 然後下次 timer 觸發時 再出現一次汽球....直到程式結束!!! 只有一點 就是 balloon 要十秒鐘左右消失 當然 每次我去 balloon 按個 button 就會消失 如果 我想改成 每個 balloon 只有一秒鐘就自動消失 我要怎麼做?!........ Thanks in advance ~~~ !! unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,ShellAPI; const NIF_INFO = $10; NIF_MESSAGE = 1; NIF_ICON = 2; NOTIFYICON_VERSION = 3; NIF_TIP = 4; NIM_SETVERSION = $00000004; NIM_SETFOCUS = $00000003; NIIF_INFO = $00000001; NIIF_WARNING = $00000002; NIIF_ERROR = $00000003; NIN_BALLOONSHOW = WM_USER 2; NIN_BALLOONHIDE = WM_USER 3; NIN_BALLOONTIMEOUT = WM_USER 4; NIN_BALLOONUSERCLICK = WM_USER 5; NIN_SELECT = WM_USER 0; NINF_KEY = $1; NIN_KEYSELECT = NIN_SELECT or NINF_KEY; {other constants can be found in vs.net---vc7's dir: PlatformSDK\Include\ShellAPI.h} {define the callback message} TRAY_CALLBACK = WM_USER $7258; {new NotifyIconData structure definition} type PNewNotifyIconData = ^TNewNotifyIconData; TDUMMYUNIONNAME = record case Integer of 0: (uTimeout: UINT); 1: (uVersion: UINT); end; TNewNotifyIconData = record cbSize: DWORD; Wnd: HWND; uID: UINT; uFlags: UINT; uCallbackMessage: UINT; hIcon: HICON; //Version 5.0 is 128 chars, old ver is 64 chars szTip: array [0..127] of Char; dwState: DWORD; //Version 5.0 dwStateMask: DWORD; //Version 5.0 szInfo: array [0..255] of Char; //Version 5.0 DUMMYUNIONNAME: TDUMMYUNIONNAME; szInfoTitle: array [0..63] of Char; //Version 5.0 dwInfoFlags: DWORD; //Version 5.0 end; type TForm1 = class(TForm) Timer1: TTimer; Button2: TButton; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure open1Click(Sender: TObject); procedure close1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } iGlbCnt : integer ; IconData: TNewNotifyIconData; procedure SysTrayIconMsgHandler(var Msg: TMessage); message TRAY_CALLBACK; procedure AddSysTrayIcon; procedure ShowBalloonTips; procedure DeleteSysTrayIcon; //procedure WndProc(var Msg : TMessage); override; public { Public declarations } //IconData : TNotifyIconData; IconCount : integer; end; var Form1: TForm1; implementation {$R *.dfm} { procedure TForm1.WndProc(var Msg : TMessage); var p : TPoint; begin case Msg.Msg of WM_USER 1: case Msg.lParam of WM_LBUTTONDOWN: begin // 在圖上按了右鍵 open1Click(form1); end; end; end; inherited; end; } procedure TForm1.SysTrayIconMsgHandler(var Msg: TMessage); begin case Msg.lParam of WM_MOUSEMOVE:; WM_LBUTTONDOWN: open1Click(form1); WM_LBUTTONUP:; WM_LBUTTONDBLCLK:; WM_RBUTTONDOWN:; WM_RBUTTONUP:; WM_RBUTTONDBLCLK:; //followed by the new messages NIN_BALLOONSHOW: {Sent when the balloon is shown} ShowMessage('NIN_BALLOONSHOW'); NIN_BALLOONHIDE: {Sent when the balloon disappears?Rwhen the icon is deleted, for example. This message is not sent if the balloon is dismissed because of a timeout or mouse click by the user. } ShowMessage('NIN_BALLOONHIDE'); NIN_BALLOONTIMEOUT: {Sent when the balloon is dismissed because of a timeout.} ShowMessage('NIN_BALLOONTIMEOUT'); NIN_BALLOONUSERCLICK: {Sent when the balloon is dismissed because the user clicked the mouse. Note: in XP there's Close button on he balloon tips, when click the button, send NIN_BALLOONTIMEOUT message actually.} ShowMessage('NIN_BALLOONUSERCLICK'); end; end; {AddSysTrayIcon procedure add an icon to notification area} procedure TForm1.AddSysTrayIcon; begin IconData.cbSize := SizeOf(IconData); IconData.Wnd := AllocateHWnd(SysTrayIconMsgHandler); {SysTrayIconMsgHandler is then callback message' handler} IconData.uID := 0; IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; IconData.uCallbackMessage := TRAY_CALLBACK; //user defined callback message IconData.hIcon := Application.Icon.Handle; //an Icon's Handle IconData.szTip := '成交回報'; if not Shell_NotifyIcon(NIM_ADD, @IconData) then ShowMessage('add fail'); end; {ShowBalloonTips procedure carry out the new feature: Balloon Tips} procedure TForm1.ShowBalloonTips; var TipInfo, TipTitle: string; begin IconData.cbSize := SizeOf(IconData); IconData.uFlags := NIF_INFO; TipInfo := '台指02 成交十口 價格: ' inttostr(iGlbCnt); strPLCopy(IconData.szInfo, TipInfo, SizeOf(IconData.szInfo) - 1); IconData.DUMMYUNIONNAME.uTimeout := 3000; TipTitle := '成交回報'; strPLCopy(IconData.szInfoTitle, TipTitle, SizeOf(IconData.szInfoTitle) - 1); IconData.dwInfoFlags := NIIF_INFO; //NIIF_ERROR; //NIIF_WARNING; Shell_NotifyIcon(NIM_MODIFY, @IconData); {in my testing, the following code has no use} IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION; if not Shell_NotifyIcon(NIM_SETVERSION, @IconData) then ShowMessage('setversion fail'); end; {here's the deletion procedure} procedure TForm1.DeleteSysTrayIcon; begin DeallocateHWnd(IconData.Wnd); if not Shell_NotifyIcon(NIM_DELETE, @IconData) then ShowMessage('delete fail'); end; procedure TForm1.FormCreate(Sender: TObject); begin AddSysTrayIcon; ShowBalloonTips; end; procedure TForm1.FormDestroy(Sender: TObject); begin DeleteSysTrayIcon; end; procedure TForm1.Timer1Timer(Sender: TObject); begin iGlbCnt := iGlbCnt 1 ; ShowBalloonTips; end; procedure TForm1.open1Click(Sender: TObject); begin Form1.Show; ShowWindow(Application.Handle, SW_HIDE); end; procedure TForm1.close1Click(Sender: TObject); begin Shell_NotifyIcon(NIM_DELETE, @IconData); Application.ProcessMessages; Application.Terminate; end; procedure TForm1.Button1Click(Sender: TObject); begin close1Click(sender); end; procedure TForm1.Button2Click(Sender: TObject); begin Form1.hide; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin //Action := caNone; //Form1.Hide; Shell_NotifyIcon(NIM_DELETE, @IconData); Application.ProcessMessages; Application.Terminate; end; end.
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-28 13:11:15 IP:202.39.xxx.xxx 未訂閱
縮短 Timer1 的 Interval 屬性試試
RogerHer
一般會員


發表:11
回覆:39
積分:10
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-28 16:42:31 IP:61.221.xxx.xxx 未訂閱
在想要隱藏的時候加入以下的 code  
  with IconData do
  begin
    uFlags := uFlags or NIF_INFO;
    StrPCopy(szInfo, '');
  end;
  Shell_NotifyIcon(NIM_MODIFY, @IconData);
 
hedge
一般會員


發表:4
回覆:10
積分:2
註冊:2004-09-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-30 08:06:13 IP:202.39.xxx.xxx 未訂閱
You are right !!!! .............. It is exactly what I want ...Thanks !!!!    
引言: 在想要隱藏的時候加入以下的 code
  with IconData do
  begin
    uFlags := uFlags or NIF_INFO;
    StrPCopy(szInfo, '');
  end;
  Shell_NotifyIcon(NIM_MODIFY, @IconData);
 
系統時間:2024-05-09 7:38:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!