有谁能告诉我最小化控件在那里能找到?(10分)

L

laijf

Unregistered / Unconfirmed
GUEST, unregistred user!
我知道C++中本身就带有一个最小化控件,可以实现窗口最小化后只在右下角显示一个图标
但在DELPHI中我找遍了都没找到相同功能的控件,有谁能告诉我吗?在那里可以找到,我用
的是DELPHI6.0企业版
 
unit NotifyIcon;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
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;
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.
 
要写这么多呀?
难道就没有一个控件能搞定吗?
C++里那个控件就很好用
 
DELPHI没有这种控件,要在右下角显示图标,要用API才能实现。
要最小化application.minization
 
这就是个控件的源代码,把它安装进DELPHI就行了,要用时从组件面板中选!

不要告诉我你不会安装!
 
能不能直接把C++里的控件转过来用
 
到www.playicq.com源码空间去下载《Delphi深度历险》这个资料
里面有完整的解决方案。注意,要先在该网站注册。还可以下载到
许多有用的东西。
 
我有一个可视化的控件,还有例子,非常简单易用。

不过,你的分也太少了吧。

给我来封信,晚上给你发过去(东东在单位,下午带回来)。

EMAIL:b5790930@pub.xz.jsinfo.net QQ:584740
 
ysai呵呵,好马上看学学,我没安装过,能提示一下吗?我是个菜鸟
 
不好意思小弟确实好像分太少了,呵呵没办法呀~!
谢谢你们的帮助
 
多人接受答案了。
 
兄弟,太。。。了吧,早知道不帮你喽
 

Similar threads

D
回复
0
查看
850
DelphiTeacher的专栏
D
D
回复
0
查看
817
DelphiTeacher的专栏
D
D
回复
0
查看
893
DelphiTeacher的专栏
D
D
回复
0
查看
734
DelphiTeacher的专栏
D
顶部