unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
PopupMenu1: TPopupMenu;
asdf1: TMenuItem;
N2342341: TMenuItem;
N1: TMenuItem;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure WndProc(var Msg: TMessage); override; // tray icon 的 call back function
{ Public declarations }
end;
const
WM_MYTRAYNOTIFY=WM_USER+1; //定義 wm message
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
tray_nid: TNotifyIconData;
tray_icon: TIcon;
begin
tray_icon:= TIcon.Create;
tray_icon.LoadFromFile('COLOR_BL.ICO');
tray_nid.cbSize := sizeof(tray_nid);
tray_nid.Wnd := self.Handle;
// blueicon 設定uID為 200
tray_nid.uID := 200;
tray_nid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
// NIF_MESSAGE 設定 message wm_xxx
// NIF_ICON 設定 ICON
// NIF_TIP 設定 提示訊息
tray_nid.hIcon := tray_icon.Handle;
tray_nid.uCallbackMessage := WM_MYTRAYNOTIFY;
StrPCopy(tray_nid.szTip, '工具任按鈕提示');
Shell_NotifyIcon(NIM_ADD, @tray_nid);
tray_icon.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
tray_nid: TNotifyIconData;
begin
tray_nid.cbSize := sizeof(tray_nid);
tray_nid.Wnd := self.Handle;
// blueicon 設定為 200
tray_nid.uID := 200;
Shell_NotifyIcon(NIM_DELETE, @tray_nid);
end;
procedure TForm1.WndProc(var Msg: TMessage);
var
pt: TPOINT;
curpos, curaction, curicon: string;
begin
if Msg.Msg = WM_MYTRAYNOTIFY then
begin
// ICON 的 uID
case Msg.WParam of
200: curicon := 'blue icon mouse action: ';
300: curicon := 'green icon mouse action: ';
end;
GetCursorPos(pt);
curpos := 'X: '+IntToStr(pt.X)+', Y: '+IntToStr(pt.Y);
// 滑鼠的按鍵動作
case Msg.LParam of
WM_LBUTTONDOWN: curaction := 'Left Button Down ';
WM_RBUTTONDOWN: curaction := 'Right Button Down ';
WM_LBUTTONUP: curaction := 'Left Button Up ';
WM_RBUTTONUP:
begin
curaction := 'Right Button up ';
SetForegroundWindow(Handle); //隨意地方按左鍵就能消除
popupmenu1.popup(pt.X,pt.Y );
PostMessage(Handle,WM_NULL,0,0);
end;
WM_MOUSEMOVE: curaction := 'Mouse Move ';
WM_LBUTTONDBLCLK: curaction := 'Left Button DoubleClick ';
WM_RBUTTONDBLCLK: curaction := 'Right Button DoubleClick ';
end;
Memo1.Lines.Add(curicon+' '+curaction+' '+curpos); //訊息由目前的圖示,滑鼠位置及滑鼠按鍵 組成
end;
inherited;
end;
end.
星期日, 9月 02, 2007
右下角工具列顯示,並有按右鍵的功能
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言