回覆列表
  • 1 # 扶尾貓半島似水浮生

    Shell_NotifyIcon這個API可以實現系統托盤圖示功能,然後你在自定義一下最小化的訊息就可以了,圖示功能有個例子

    托盤就是在工作列右下角的小圖示。建立、更改、刪除只需要一個Windows API就能實現。這個函式叫做Shell_NotifyIcon()。這個函式和其他處理Windows 外殼的函式都包含在ShellAPI單元中。本例程在視窗建立時在工作列的右下角建立一個托盤圖示。圖示由兩個ICON交替出現。當視窗最小化時工作列中只有托盤圖示,當左鍵單擊托盤圖示視窗恢復。圖示停止交替。

    unit Unit1;

    interface

    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,SHELLAPI,

    Menus, Dialogs,

    ExtCtrls, ImgList;

    const

    MI_ICONEVENT = WM_USER + 1;

    ICON_ID = 10;

    type

    TForm1 = class(TForm)

    Timer1: TTimer;

    PopupMenu2: TPopupMenu;

    N1: TMenuItem;

    ImageList1: TImageList;

    procedure N1Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

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

    procedure Timer1Timer(Sender: TObject);

    private

    procedure modifyicon;

    procedure IconOnClick(var message: TMessage); MESSAGE MI_ICONEVENT;

    procedure tranmessage(var m:TWMSYSCOMMAND); message WM_SYSCOMMAND;

    public

    { Public declarations }

    end;

    var

    Form1: TForm1;

    ydic:array [0..1] of ticon;

    icint:integer;

    xsyc:BOOLEAN;

    implementation

    {$R *.DFM}

    procedure TForm1.N1Click(Sender: TObject);

    begin

    APPLICATION.Terminate ;

    end;

    procedure TForm1.FormCreate(Sender: TObject);

    var

    IconData: TNotifyIconData;

    begin

    xsyc:=true;

    ydic[0]:=ticon.Create;

    ydic[1]:=ticon.Create;

    ydic[0].Handle :=loadicon(hinstance,"icon0");//資原始檔(ICONS.RES)

    ydic[1].Handle :=loadicon(hinstance,"icon1");

    IconData.cbSize:=SizeOf(IconData );

    IconData.Wnd:= form1.Handle;

    IconData.uID:= ICON_ID;

    IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;

    IconData.uCallBackMessage := MI_ICONEVENT;

    IconData.hIcon :=ydic[0].Handle;

    IconData.szTip := "我笑、我笑、笑笑笑";

    icint:=0;

    Shell_NotifyIcon( NIM_ADD, @IconData );

    ShowWindow(Application.Handle, SW_HIDE );

    end;

    procedure TForm1.FormDestroy(Sender: TObject);

    var

    IconData: TNotifyIconData;

    begin //解除安裝圖示

    IconData.cbSize := SizeOf( IconData );

    IconData.Wnd :=form1.Handle;

    IconData.uID := ICON_ID;

    Shell_NotifyIcon( NIM_DELETE, @IconData );

    end;

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

    var

    IconData: TNotifyIconData;

    begin //解除安裝圖示

    IconData.cbSize := SizeOf( IconData );

    IconData.Wnd :=form1.Handle;

    IconData.uID := ICON_ID;

    Shell_NotifyIcon( NIM_DELETE, @IconData );

    end;

    procedure TForm1.Timer1Timer(Sender: TObject);

    begin

    modifyicon

    end;

    procedure TForm1.modifyicon;

    var

    IconData: TNotifyIconData;

    begin

    IconData.cbSize := SizeOf( IconData );

    IconData.Wnd :=form1.Handle;

    IconData.uID := ICON_ID;

    icint:=(icint+1) mod 2;

    IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;

    IconData.uCallBackMessage := MI_ICONEVENT;

    icondata.hIcon:= ydic[icint].Handle;

    IconData.szTip := "我笑、我笑、笑笑笑";

    shell_notifyicon(nim_modify,@icondata);

    end;

    procedure TForm1.IconOnClick(var message: TMessage);

    var

    a:tpoint;

    begin //單擊事件

    if (message.lParam = WM_RBUTTONDOWN) then

    begin

    getcursorpos(a);

    PopupMenu2.Popup(a.x,a.y);

    end

    else if (message.lParam = WM_LBUTTONDOWN) then

    begin

    timer1.Enabled:=FALSE;

    if xsyc then

    sendmessage(form1.Handle,wm_syscommand,sc_minimize,0)

    else

    begin

    ShowWindow(Application.Handle,SW_RESTORE);//SW_maximize

    setforegroundwindow(form1.handle);

    xsyc:=true;

    end;

    end;

    end;

    procedure TForm1.tranmessage(var m: TWMSYSCOMMAND);

    begin

    if m.CmdType=SC_MINIMIZE then

    begin

    timer1.Enabled :=true;

    sendmessage(Application.Handle,WM_SYSCOMMAND,SC_MINimize,0);

    ShowWindow(Application.Handle, SW_HIDE );

    xsyc:=false;

    end

    else

    inherited;

    end;

    end.

    最小化訊息過載可以這樣

    procedure pgame(var msg:twmsyscommand);message wm_syscommand;

    procedure Tmainfrm.pgame(var msg: twmsyscommand); //視窗最小化

    begin

    if msg.CmdType=SC_MINIMIZE then

    begin

    //處理程式碼

    end;

    inherited;

    end;

  • 中秋節和大豐收的關聯?
  • 實習支教指導教師評語?