TNotifyIcon 控制元件1.01 (轉)
TNotifyIcon 控制元件1.01 (轉)[@more@]TNotifyIcon 1.01 (Build use 3.0) 說明:
作用:
往通知區加圖示,並可顯示,隱藏,修改這個圖示.
屬性(properties):
NotifyIcon:TIcon 欲加在通知區的圖示
IsVisible:boolean NotifyIcon是否顯示的屬性
Title:string 通知區圖示上的提示(最多64個字元)
PopupMenu:TPopupMenu 點選通知區圖示彈出的選單
PopupStyle:TPopupStyle 彈出選單的方式
TPopupStyle=Set of
(Left_Click,Right_Click,Left_Click,Right_DbClick);
方法(methods):
ShowIcon 將圖示顯示在通知區上
HIcon 將通知區上的圖示隱藏
ModifyIcon 修改通知區上的圖示(若IsVisible=false,則不顯示出來)
Create(AOwner: TComponent); override; 構造方法
Destroy; override; 析構方法
事件(Events):
OnIconMouseDown:
procedure(Sender:T;x,y:;WhoButton:TWhoButton) of
Object;
(
在Mouse點選通知區上的圖示時發生,x,y為Mouse在螢幕上的座標,
WhoButton=b_Left為點選左鍵,WhoButton=b_Right為點選右鍵,
)
OnIconDoubleClick:
procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of
Object;
(
在Mouse雙擊通知區上的圖示時發生,x,y為Mouse在螢幕上的座標,
WhoButton=b_Left為雙擊左鍵,WhoButton=b_Right為雙擊右鍵,
)
關於Demo:
這個演示給出了TNotifyIcon的基本用法.
包含:
NotifyIcon.dcr
NotifyIcon.pas
DemoUnit.pas
DemoUnit.dfm
PopUnit.pas
PopUnit.dfm
Demo.dpr
Readme.txt
宣告:
TNotifyIcon 控制元件 V 1.01
1.這是一個免費控制元件.
2.如果你使用它,請發一個E-給作者,謝謝.
3我在Delphi3.0 & 4.0 上使用成功
4.若要傳播它,請完全分發上述8個檔案
作者 南昌大學計算系95(1) 付昱綱 1998.8.17 21:50
">fyg@163.net
unit NotifyIcon;
interface
uses
, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
DsgnIntf,,ExtCtrls,Menus;
const
WM_MY_Notify=WM_USER+100;
type
TPopupStyle=Set of
(Left_Click,Right_Click,Left_DbClick,Right_DbClick);
TWhoButton=(b_Left,b_Right);
TMouseEvent=
procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)
of Object;
//---------class TNotifyIcon---------
TNotifyIcon = class(TCustomControl)
private
{ Private declarations }
FIcon:TIcon;
FPda:PNOTIFYICONDATA;
FTitle:string;
FIconVisible:boolean;
FPopupMenu:TPopupMenu;
FPopupStyle:TPopupStyle;
FOnIconMouseDown:TMouseEvent;
FOnIconDoubleClick:TMouseEvent;
procedure SetIcon(Icon:TICON);
procedure SetTitle(NewTitle:string);
function IsShowing:boolean;
procedure ShowIt(Accept:boolean);
procedure NotifyIconClick(var msg : TMessage);
Message WM_My_Notify;
protected
{ Protected declarations }
public
{ Public declarations }
property IsVisible:boolean read IsShowing write ShowIt;
constructor Create(AOwner: TComponent); override;
procedure ShowIcon;
procedure HideIcon;
destructor Destroy; override;
procedure ModifyIcon(NewIcon:TIcon);
procedure Paint;override;
published
{ Published declarations }
property Height default 33;
property Width default 33;
property NotifyIcon:TIcon read FIcon write SetIcon;
property Title:string read FTitle write SetTitle ;
property OnIconDoubleClick:TMouseEvent
read FOnIconDoubleClick write FOnIconDoubleClick;
property OnIconMouseDown:TMouseEvent
read FOnIconMouseDown write FOnIconMouseDown;
property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;
property PopupStyle:TPopupStyle read FPopupStyle
write FPopupStyle default [];
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyControl', [TNotifyIcon]);
end;
procedure TNotifyIcon.ShowIt(Accept:boolean);
begin
if Accept=true then ShowIcon
else HideIcon;
end;
procedure TNotifyIcon.Paint;
begin
if (csDesigning in ComponentState) then
begin
Width:=33;
Height:=33;
With Canvas do
begin
Brush.Color:=clInfoBk;
Ellipse(0,0,Self.Width,Self.Height);
Font.Color:=clBlue;
Brush.Style:=bsClear;
FloodFill(5,5,clInfoBk,fsBorder);
Brush.Color:=clInfoBk;
TextOut(3,Self.Height div 2-6,'Notify');
end
end;
end;
procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);
var p:TPoint;
begin
try
case msg.LParam of
WM_LBUTTONDOWN:
begin
GetCursorPos(p);
if Left_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDOWN:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Right);
end;
end;
WM_LBUTTONDBLCLK:
begin
GetCursorPos(p);
if Left_DbClick in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDBLCLk:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Right);
end;
end;
end;
except
end;
end;
function MAKELANGID(p, s:word):Cardinal;
begin
result:= (((s)shl 10) or(p));
end;
constructor TNotifyIcon.Create(AOwner: TComponent);
begin
try
inherited Create(AOwner);
FIcon:=TIcon.Create;
Height:=36;
Width:=36;
Visible:=false;
FTitle:='Welcome';
FIconVisible:=false;
//-------------set tray info---------
ParentWindow:=TWinControl(AOwner).Handle;
New(Fpda);
With FPda^ do
begin
uCallbackMessage:=WM_MY_Notify;
cbsize:=SizeOf(FPda^);
uID:=200;
wnd:=Handle;
uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;
end;
if (csDesigning in ComponentState) then
begin
if GetUserDefaultLCID =
MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) then
Application.MessageBox(
'Write by 南昌大學 付昱綱'#13#13'E-mail:fyg@163.net'#13#13'
1998.8.17',
'TNotifyIcon 控制元件 V 1.01',MB_OK+ MB_ICONINFORMATION)
else
Application.MessageBox(
'Write by NanChang University
FuYuGang'#13#13'E-mail:fyg@163.net'#13#13' 1998.8.17',
'TNotifyIcon Component V 1.01',MB_OK+ MB_ICONINFORMATION);
end;
except
ShowMessage('TNotifyIcon Create error');
end;
end;
procedure TNotifyIcon.SetIcon(Icon:TICON);
begin
FIcon.Assign(Icon);
end;
procedure TNotifyIcon.ShowIcon;
begin
try
if FIcon.Handle=0 then
begin
Exit;
end;
if FIcon.Handle<>FPda^.hIcon then
HideIcon;
if FIconVisible=false then
begin
FPda^.hIcon:=FIcon.handle;
FIconVisible:=true;
Shell_NotifyIcon(NiM_ADD,FPda);
end;
except
ShowMessage('TNotifyIcon Show Error ');
end;
end;
procedure TNotifyIcon.HideIcon;
begin
try
if FIconVisible then
begin
FIconVisible:=false;
Shell_NotifyIcon(NiM_DELETE,FPda);
end;
except
ShowMessage('TNotifyIcon Hide Error');
end;
end;
procedure TNotifyIcon.SetTitle(NewTitle:string);
begin
FTitle:=NewTitle;
StrCopy(FPda^.szTip,PChar(FTitle));
if FIconVisible then
begin
HideIcon;
ShowIcon;
end;
end;
destructor TNotifyIcon.Destroy;
begin
try
HideIcon;
Dispose(FPda);
FIcon.Free;
inherited Destroy;
except
ShowMessage('TNotifyIcon Destroy Error');
end;
end;
procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);
begin
try
SetIcon(NewIcon);
FPda^.hIcon:=FIcon.handle;
if FIconVisible then
Shell_NotifyIcon(NiM_Modify,FPda);
except
ShowMessage('TNotifyIcon Modify Error');
end;
end;
function TNotifyIcon.IsShowing:boolean;
begin
Result:=FIconVisible;
end;
end.
作用:
往通知區加圖示,並可顯示,隱藏,修改這個圖示.
屬性(properties):
NotifyIcon:TIcon 欲加在通知區的圖示
IsVisible:boolean NotifyIcon是否顯示的屬性
Title:string 通知區圖示上的提示(最多64個字元)
PopupMenu:TPopupMenu 點選通知區圖示彈出的選單
PopupStyle:TPopupStyle 彈出選單的方式
TPopupStyle=Set of
(Left_Click,Right_Click,Left_Click,Right_DbClick);
方法(methods):
ShowIcon 將圖示顯示在通知區上
HIcon 將通知區上的圖示隱藏
ModifyIcon 修改通知區上的圖示(若IsVisible=false,則不顯示出來)
Create(AOwner: TComponent); override; 構造方法
Destroy; override; 析構方法
事件(Events):
OnIconMouseDown:
procedure(Sender:T;x,y:;WhoButton:TWhoButton) of
Object;
(
在Mouse點選通知區上的圖示時發生,x,y為Mouse在螢幕上的座標,
WhoButton=b_Left為點選左鍵,WhoButton=b_Right為點選右鍵,
)
OnIconDoubleClick:
procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of
Object;
(
在Mouse雙擊通知區上的圖示時發生,x,y為Mouse在螢幕上的座標,
WhoButton=b_Left為雙擊左鍵,WhoButton=b_Right為雙擊右鍵,
)
關於Demo:
這個演示給出了TNotifyIcon的基本用法.
包含:
NotifyIcon.dcr
NotifyIcon.pas
DemoUnit.pas
DemoUnit.dfm
PopUnit.pas
PopUnit.dfm
Demo.dpr
Readme.txt
宣告:
TNotifyIcon 控制元件 V 1.01
1.這是一個免費控制元件.
2.如果你使用它,請發一個E-給作者,謝謝.
3我在Delphi3.0 & 4.0 上使用成功
4.若要傳播它,請完全分發上述8個檔案
作者 南昌大學計算系95(1) 付昱綱 1998.8.17 21:50
">fyg@163.net
unit NotifyIcon;
interface
uses
, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
DsgnIntf,,ExtCtrls,Menus;
const
WM_MY_Notify=WM_USER+100;
type
TPopupStyle=Set of
(Left_Click,Right_Click,Left_DbClick,Right_DbClick);
TWhoButton=(b_Left,b_Right);
TMouseEvent=
procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)
of Object;
//---------class TNotifyIcon---------
TNotifyIcon = class(TCustomControl)
private
{ Private declarations }
FIcon:TIcon;
FPda:PNOTIFYICONDATA;
FTitle:string;
FIconVisible:boolean;
FPopupMenu:TPopupMenu;
FPopupStyle:TPopupStyle;
FOnIconMouseDown:TMouseEvent;
FOnIconDoubleClick:TMouseEvent;
procedure SetIcon(Icon:TICON);
procedure SetTitle(NewTitle:string);
function IsShowing:boolean;
procedure ShowIt(Accept:boolean);
procedure NotifyIconClick(var msg : TMessage);
Message WM_My_Notify;
protected
{ Protected declarations }
public
{ Public declarations }
property IsVisible:boolean read IsShowing write ShowIt;
constructor Create(AOwner: TComponent); override;
procedure ShowIcon;
procedure HideIcon;
destructor Destroy; override;
procedure ModifyIcon(NewIcon:TIcon);
procedure Paint;override;
published
{ Published declarations }
property Height default 33;
property Width default 33;
property NotifyIcon:TIcon read FIcon write SetIcon;
property Title:string read FTitle write SetTitle ;
property OnIconDoubleClick:TMouseEvent
read FOnIconDoubleClick write FOnIconDoubleClick;
property OnIconMouseDown:TMouseEvent
read FOnIconMouseDown write FOnIconMouseDown;
property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;
property PopupStyle:TPopupStyle read FPopupStyle
write FPopupStyle default [];
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyControl', [TNotifyIcon]);
end;
procedure TNotifyIcon.ShowIt(Accept:boolean);
begin
if Accept=true then ShowIcon
else HideIcon;
end;
procedure TNotifyIcon.Paint;
begin
if (csDesigning in ComponentState) then
begin
Width:=33;
Height:=33;
With Canvas do
begin
Brush.Color:=clInfoBk;
Ellipse(0,0,Self.Width,Self.Height);
Font.Color:=clBlue;
Brush.Style:=bsClear;
FloodFill(5,5,clInfoBk,fsBorder);
Brush.Color:=clInfoBk;
TextOut(3,Self.Height div 2-6,'Notify');
end
end;
end;
procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);
var p:TPoint;
begin
try
case msg.LParam of
WM_LBUTTONDOWN:
begin
GetCursorPos(p);
if Left_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDOWN:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconMouseDown) then
begin
FOnIconMouseDown(Self,p.x,p.y,b_Right);
end;
end;
WM_LBUTTONDBLCLK:
begin
GetCursorPos(p);
if Left_DbClick in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Left);
end;
end;
WM_RBUTTONDBLCLk:
begin
GetCursorPos(p);
if Right_Click in FPopupStyle then
begin
SetForegroundWindow(ParentWindow);
FPopupMenu.Popup(p.x,p.y);
end;
if Assigned(FOnIconDoubleClick) then
begin
FOnIconDoubleClick(Self,p.x,p.y,b_Right);
end;
end;
end;
except
end;
end;
function MAKELANGID(p, s:word):Cardinal;
begin
result:= (((s)shl 10) or(p));
end;
constructor TNotifyIcon.Create(AOwner: TComponent);
begin
try
inherited Create(AOwner);
FIcon:=TIcon.Create;
Height:=36;
Width:=36;
Visible:=false;
FTitle:='Welcome';
FIconVisible:=false;
//-------------set tray info---------
ParentWindow:=TWinControl(AOwner).Handle;
New(Fpda);
With FPda^ do
begin
uCallbackMessage:=WM_MY_Notify;
cbsize:=SizeOf(FPda^);
uID:=200;
wnd:=Handle;
uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;
end;
if (csDesigning in ComponentState) then
begin
if GetUserDefaultLCID =
MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) then
Application.MessageBox(
'Write by 南昌大學 付昱綱'#13#13'E-mail:fyg@163.net'#13#13'
1998.8.17',
'TNotifyIcon 控制元件 V 1.01',MB_OK+ MB_ICONINFORMATION)
else
Application.MessageBox(
'Write by NanChang University
FuYuGang'#13#13'E-mail:fyg@163.net'#13#13' 1998.8.17',
'TNotifyIcon Component V 1.01',MB_OK+ MB_ICONINFORMATION);
end;
except
ShowMessage('TNotifyIcon Create error');
end;
end;
procedure TNotifyIcon.SetIcon(Icon:TICON);
begin
FIcon.Assign(Icon);
end;
procedure TNotifyIcon.ShowIcon;
begin
try
if FIcon.Handle=0 then
begin
Exit;
end;
if FIcon.Handle<>FPda^.hIcon then
HideIcon;
if FIconVisible=false then
begin
FPda^.hIcon:=FIcon.handle;
FIconVisible:=true;
Shell_NotifyIcon(NiM_ADD,FPda);
end;
except
ShowMessage('TNotifyIcon Show Error ');
end;
end;
procedure TNotifyIcon.HideIcon;
begin
try
if FIconVisible then
begin
FIconVisible:=false;
Shell_NotifyIcon(NiM_DELETE,FPda);
end;
except
ShowMessage('TNotifyIcon Hide Error');
end;
end;
procedure TNotifyIcon.SetTitle(NewTitle:string);
begin
FTitle:=NewTitle;
StrCopy(FPda^.szTip,PChar(FTitle));
if FIconVisible then
begin
HideIcon;
ShowIcon;
end;
end;
destructor TNotifyIcon.Destroy;
begin
try
HideIcon;
Dispose(FPda);
FIcon.Free;
inherited Destroy;
except
ShowMessage('TNotifyIcon Destroy Error');
end;
end;
procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);
begin
try
SetIcon(NewIcon);
FPda^.hIcon:=FIcon.handle;
if FIconVisible then
Shell_NotifyIcon(NiM_Modify,FPda);
except
ShowMessage('TNotifyIcon Modify Error');
end;
end;
function TNotifyIcon.IsShowing:boolean;
begin
Result:=FIconVisible;
end;
end.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-998259/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ACE_Reactor (V1.01)React
- 控制元件 (轉)控制元件
- 1.01 容器技術和docker簡介Docker
- 工具提示控制元件(轉)控制元件
- JDPack Version 1.01 外殼完全分析筆記筆記
- 列表檢視控制元件(轉)控制元件
- 子視窗控制元件(轉)控制元件
- 字幕圖示控制元件 (轉)控制元件
- 控制元件treeview的使用 (轉)控制元件View
- .NET 控制元件轉圖片控制元件
- 改良控制元件-Delphi自帶控制元件Bug的消除 (轉)控制元件
- DataList控制元件也玩分頁-轉貼 (轉)控制元件
- 動態移動控制元件 (轉)控制元件
- 樹型檢視控制元件(轉)控制元件
- 樹形控制元件比較 (轉)控制元件
- BCB 窗體透明控制元件 (轉)控制元件
- 使用loader方式破解 arm 1.01 (6千字)
- 自定義控制元件中的控制元件呼叫引用控制元件的頁面裡的函式 (轉)控制元件函式
- Android ListVeiw控制元件(轉載整理)Android控制元件
- 在Delphi中使用IP控制元件 (轉)控制元件
- .NET中新增控制元件陣列 (轉)控制元件陣列
- combo box控制元件的使用 (轉)控制元件
- 在delphi中使用flash控制元件 (轉)控制元件
- DataGrid控制元件通用列印類. (轉)控制元件
- 開發自己的Excell控制元件 (轉)Excel控制元件
- HTML事件的控制元件觸發 (轉)HTML事件控制元件
- 對Delphi控制元件的一點改良 (轉)控制元件
- TWebBrowser控制元件與MSHTML庫連線 (轉)Web控制元件HTML
- C#實現控制元件陣列 (轉)C#控制元件陣列
- SysListView控制元件類的訊息常量 (轉)View控制元件
- Vb中控制元件的自動排列 (轉)控制元件
- 為DataGrid新增CheckBox控制元件 (轉)控制元件
- Java中BigDecimal的使用(1.01+2.02=3.0300000000000002)JavaDecimal
- 身份證資訊查詢與校驗(IdCard) v1.01
- 建立ASP.NET WEB自定義控制元件(轉)ASP.NETWeb控制元件
- 對Delphi控制元件的一點改良(二) (轉)控制元件
- delphi 控制元件的拿來主義(一) (轉)控制元件
- 控制元件破解指南(轉貼) (4千字)控制元件