當前位置:編程學習大全網 - 源碼下載 - delphi怎麽寫“最小化到系統托盤”(有控件最好)

delphi怎麽寫“最小化到系統托盤”(有控件最好)

uses ShellAPI;

const

MY_MESSAGE=WM_USER+100;

public

{ Public declarations }

procedure proOnIconNotify(var MyMeg:TMessage);message MY_MESSAGE;

procedure TfrmTimer.FormCreate(Sender: TObject);

var

nid:TNotifyIconData;

begin

SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //不在任務欄顯示

//創建系統托盤圖標開始

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.Wnd:=Handle; //主窗口句柄

nid.uID:=1; //內部標識,可設為任意數,但刪除時應保持壹致

nid.hIcon:=Application.Icon.Handle; //要加入的圖標句柄,可任意指

nid.szTip:='定時啟動器'; //提示字符串

nid.uCallbackMessage:=MY_MESSAGE; //回調函數消息

nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE; //指明哪些字段有

if not Shell_NotifyIcon(NIM_ADD,@nid)then

MessageBox(handle,'創建系統托盤圖標失敗!','錯誤',MB_ICONHAND + MB_OK);

//創建系統托盤圖標結束

end;

procedure TfrmTimer.FormDestroy(Sender: TObject);

var

nid:TNotifyIconData;

begin

//刪除系統托盤圖標 開始

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.uID:=1; //內部標識,與加入小圖標時的數壹致

nid.Wnd:=Handle; //主窗口句柄

Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小圖標

//刪除系統托盤圖標 結束

end;

procedure TfrmTimer.FormActivate(Sender: TObject);

begin

SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW); //在任務欄顯示

end;

procedure TfrmTimer.proOnIconNotify(var MyMeg:TMessage);

begin

Case MyMeg.LParam of

WM_LBUTTONDBLCLK,WM_RBUTTONDOWN,WM_LBUTTONDOWN:

frmTimer.Show;

end;

end;uses ShellAPI;

const

MY_MESSAGE=WM_USER+100;

public

{ Public declarations }

//點擊系統托盤圖標事件

procedure proOnIconNotify(var MyMeg:TMessage);message MY_MESSAGE;

procedure TfrmTimer.FormCreate(Sender: TObject);

var

nid:TNotifyIconData;

begin

SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //不在任務欄顯示

//創建系統托盤圖標開始

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.Wnd:=Handle; //主窗口句柄

nid.uID:=1; //內部標識,可設為任意數,但刪除時應保持壹致

nid.hIcon:=Application.Icon.Handle; //要加入的圖標句柄,可任意指

nid.szTip:='定時啟動器'; //提示字符串

nid.uCallbackMessage:=MY_MESSAGE; //回調函數消息

nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE; //指明哪些字段有

if not Shell_NotifyIcon(NIM_ADD,@nid)then

MessageBox(handle,'創建系統托盤圖標失敗!','錯誤',MB_ICONHAND + MB_OK);

//創建系統托盤圖標結束

end;

procedure TfrmTimer.FormClose(Sender: TObject; var Action: TCloseAction);

begin

if(xPlanCount<1)then

proSvLog('程序關閉。')

else

begin

if(MessageBox(handle,'關閉程序將清理所有的定時啟動任務,是否確認關閉?','註意',MB_YESNO+MB_ICONINFORMATION)=ID_NO)then

begin

Action:=caNone;

exit;

end;

Hide();

proSvLog('程序將關閉,開始清理線程!');

while(xPlanCount>0)do

begin

proDelPlan(StrToInt(sgList.Cells[0,xPlanCount]));

end;

while(xTHreadCount>0)do

begin

Application.ProcessMessages;//解決循環獨占問題以響應外部事件

end;

proSvLog('線程清理完成,程序關閉!');

end;

end;

procedure TfrmTimer.FormDestroy(Sender: TObject);

var

nid:TNotifyIconData;

begin

//刪除系統托盤圖標 開始

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.cbSize:=sizeof(nid); //nid變量的字節數

nid.uID:=1; //內部標識,與加入小圖標時的數壹致

nid.Wnd:=Handle; //主窗口句柄

Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小圖標

//刪除系統托盤圖標 結束

end;

procedure TfrmTimer.FormActivate(Sender: TObject);

begin

SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW); //在任務欄顯示

end;

procedure TfrmTimer.proOnIconNotify(var MyMeg:TMessage);//點擊系統圖標事件

begin

Case MyMeg.LParam of

WM_LBUTTONDBLCLK,WM_RBUTTONDOWN,WM_LBUTTONDOWN:

frmTimer.Show;

end;

end;

formClose()事件的代碼直接無視吧,這個插代碼的功能用著壹肚子火。

第二個問題不懂,幫不了妳

  • 上一篇:股票K線看法?簡單說明,什麽均線線超過或低於什麽線時是漲跌的預測
  • 下一篇:吃透纏論核心,股票走勢壹目了然
  • copyright 2024編程學習大全網