分享
 
 
 

TNotifyIcon 控件1.01

王朝delphi·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

TNotifyIcon 控件1.01 (Build use Delphi 3.0) 说明:

作用:

往通知区加图标,并可显示,隐藏,修改这个图标.

属性(properties):

NotifyIcon:TIcon 欲加在通知区的图标

IsVisible:boolean NotifyIcon是否显示的属性

Title:string 通知区图标上的提示(最多64个字符)

PopupMenu:TPopupMenu 点击通知区图标弹出的菜单

PopupStyle:TPopupStyle 弹出菜单的方式

TPopupStyle=Set of

(Left_Click,Right_Click,Left_DbClick,Right_DbClick);

方法(methods):

ShowIcon 将图标显示在通知区上

HideIcon 将通知区上的图标隐藏

ModifyIcon 修改通知区上的图标(若IsVisible=false,则不显示出来)

Create(AOwner: TComponent); override; 构造方法

Destroy; override; 析构方法

事件(Events):

OnIconMouseDown:

procedure(Sender:TObject;x,y:Word;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-Mail给作者,谢谢.

3我在Delphi3.0 & 4.0 上使用成功

4.若要传播它,请完全分发上述8个文件

作者 南昌大学计算系95(1) 付昱纲 1998.8.17 21:50

E-mail fyg@163.net

unit NotifyIcon;

interface

uses

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

Dialogs,

DsgnIntf,ShellApi,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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有