乙個托盤程式

2021-04-18 07:19:38 字數 3846 閱讀 4499

unit mainunit;

inte***ce

uses

windows, messages, sysutils, classes, graphics, controls, forms, dialogs,

menus, shellapi, extctrls;

const

icon_id= 1;

mi_iconevent= wm_user+ 1;

type

tmainform = class(tform)

popupmenu1: tpopupmenu;

n1: tmenuitem;

n2: tmenuitem;

n3: tmenuitem;

procedure formcreate(sender: tobject);

procedure formclose(sender: tobject; var action: tcloseaction);

procedure formactivate(sender: tobject);

procedure n1click(sender: tobject);

procedure n2click(sender: tobject);

procedure n3click(sender: tobject);

private

procedure setupicon; //在托盤中安裝圖示

procedure changeicon(s: boolean); //改變托盤中的圖示

procedure freeicon; //在托盤中釋放圖示

procedure icononclick(var msg: tmessage); message mi_iconevent; //托盤圖示電擊事件

public

end;

var mainform: tmainform;

normalicon, disabledicon: ticon; //正常和失效情況下的圖示

status: boolean; //標誌是「使用狀態」還是「禁用狀態」

apath: string;

implementation

uses showunit;

procedure tmainform.setupicon;

var icondata: tnotifyicondata;

begin

normalicon:= ticon.create;

disabledicon:= ticon.create;

normalicon.loadfromfile(apath+ '1.ico');

disabledicon.loadfromfile(apath+ '2.ico');

icondata.cbsize:= sizeof(icondata);

icondata.wnd:= handle;

icondata.uid:= icon_id;

icondata.uflags:= nif_icon or nif_message or nif_tip;

icondata.ucallbackmessage:= mi_iconevent;

icondata.hicon:= normalicon.handle;

icondata.sztip:= '新增托盤圖示';

shell_notifyicon(nim_add, @icondata);

end;

procedure tmainform.changeicon(s: boolean);

var icondata: tnotifyicondata;

begin

icondata.cbsize:= sizeof(icondata);

icondata.wnd:= handle;

icondata.uid:= icon_id;

if s= false then

begin

icondata.hicon:= disabledicon.handle;

status:= false;

n1.enabled:= false;

endelse

begin

icondata.hicon:= normalicon.handle;

status:= true;

n1.enabled:= true;

end;

icondata.uflags:= nif_icon;

shell_notifyicon(nim_modify, @icondata);

end;

procedure tmainform.freeicon;

var icondata: tnotifyicondata;

begin

icondata.cbsize:= sizeof(icondata);

icondata.wnd:= handle;

icondata.uid:= icon_id;

shell_notifyicon(nim_delete, @icondata);

end;

procedure tmainform.icononclick;

var pt: tpoint;

begin

if (msg.lparam= wm_lbuttondown) and (status= true) then

showform.show;

if (msg.lparam= wm_rbuttondown) then

begin

getcursorpos(pt);

popupmenu1.popup(pt.x, pt.y);

end;

end;

procedure tmainform.formcreate(sender: tobject);

begin

apath:= extractfilepath(paramstr(0));

status:= true;

setupicon;

changeicon(true);

end;

procedure tmainform.formclose(sender: tobject; var action: tcloseaction);

begin

freeicon;

normalicon.free;

disabledicon.free;

end;

procedure tmainform.formactivate(sender: tobject);

begin

mainform.width:= 0;

mainform.height:= 0;

end;

procedure tmainform.n1click(sender: tobject);

begin

showform.show;

end;

procedure tmainform.n2click(sender: tobject);

begin

if status= true then

begin

changeicon(false);

n2.caption:= '使用';

endelse

begin

changeicon(true);

n2.caption:= '禁用';

end;

end;

procedure tmainform.n3click(sender: tobject);

begin

close;

end;

end.

c 托盤程式

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system.window...

在乙個程式中啟動另外乙個程式

最近剛剛開始工作,發現在學校學習的那些基本上知識打打基礎而已,在實際的專案運作中根本就沒用。革命尚未成功,通知仍需努力啊 嘿嘿 上正題 因為我們需要做乙個類似於監控的系統,這樣的話就涉及到多個程式需要同時執行,並且需要有乙個程式 去控制另外乙個程式,之前沒有做過,也沒見過,不過還好,有一同事之前做過...

乙個公升級程式

首先來的是資料實體 1 public class fileent24 5public string src 67 public string version 89 public int size 1011 public updateoption option 12 1314 public enum ...