使用第三方控件TRAYICON吧,它可以帮你解决问题。
解决方案 »
- quickreport 如何一页只打印一条记录,有几条打印几页
- 毛遂自荐寻delphi兼职
- 求一个图片封装到DLL里面的例程
- 怎么编一个撤消键?
- 在mdi主窗体中加一个image控件,在改变image的尺寸时如何刷新
- playSound大多wav都能放,有些就叮一声是什么问题?
- 各位大虾,怎样把DBGrid显示的数据按text或excel文件的形式导出,急急在线等
- 为什么我作的Delphi程序编译后其他机器不能用?排除BDE等问题。
- 请问各位大虾DELPHI中怎么在程序中遍历上面的全部控件?
- 求救,关于SQLServer+Delphi的发布!
- 有谁在Delphi中实现过IDocHostUIHandler接口,高分求教
- 用READ和WIRTE可以对文本文件进行读写,怎样对文本文件指定的行进行删除。给20分(只有这么多希望大家能给予帮助))
难道没人知道吗?
请关注:注释部分
unit TrayIcon;interfaceUses Windows ,SysUtils ,Messages ,ShellAPI ,Classes,Graphics ,Forms ,Menus ,
StdCtrls ,ExtCtrls ;
Type
ENotifyIconError = class(Exception);
TTrayNotifyIcon = class (TComponent )
private
FDefaultIcon : THandle ;
FIcon : TIcon ;
FHideTask : Boolean ;
FHint : String ;
FIconVisible : Boolean ;
FPopupMenu : TPopupMenu ;
FOnClick : TNotifyEvent ;
FOnDblClick : TNotifyEvent ;
FNoShowClick : Boolean ;
FTimer : TTimer ;
Tnd : TNotifyIconData ;
Procedure SetIcon ( Value : TIcon );
procedure SetHideTask(Value : Boolean );
procedure setHint(Value : String );
Procedure SetIconVisible(Value : Boolean );
procedure setpopupMenu(value : TpopupMenu);
Procedure SendTrayMessage(Msg : DWORD ;Flags : UINT);
Function ActiveIconHandle : Thandle ;
Procedure OnButtonTimer(Sender : TObject );
Protected
procedure Loaded ;override ;
Procedure LoadDefaultIcon;Virtual ;
procedure Notification(AComponent :TComponent ;Operation :TOperation);override ;
public
constructor Create(AOwner :TComponent );override ;
destructor Destroy ;override ;
published
property Icon : TIcon read FIcon write SetIcon ;
property HideTask: boolean read FhideTask write SetHideTask default false ;
property Hint: string read Fhint write setHint ;
property IconVisible : Boolean read FIconVisible write setIconVisible default false ;
property Popupmenu :TPopupmenu Read FPopupmenu write setPopupmenu;
property Onclick : TNotifyEvent read FOnclick write FOnclick;
property OnDBlclick : TNotifyEvent read FOndblclick write FOndblclick;
end;procedure Register;
implementation
Type
TIconManager = class
Private
FHWindow : HWnd ;
Procedure TrayWndProc (Var Message :Tmessage);
public
constructor Create ;
destructor Destroy ;override ;
property HWindow : HWnd Read FHWindow write FHWindow ;
end; var
IconMgr : TIconManager ;
DDGM_TRAYICON : Integer ;
constructor TIconManager.Create ;
begin
FHWindow := ALLocateHWnd(TrayWndProc );
end ;destructor TIconManager.Destroy ;
begin
if FHWindow <>0 then DeallocateHWnd(FHWindow);
Inherited destroy ;
end ;///////////////这里
procedure TIconManager.TrayWndProc(var message : Tmessage);
var
pt: Tpoint ;
TheIcon : TTrayNotifyIcon ;
begin
with message do
begin
if (Msg = DDGM_TRAYICON) then
begin
TheIcon := TTRayNotifyIcon (WParam);
case lParam of
WM_LBUTTONDOWN:TheIcon.FTimer.Enabled := true ;
WM_LBUTTONDBLCLK :
begin
theIcon.FNoShowClick := true ;
if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick (self);
end;
WM_RBUTTONDOWN :
begin
if Assigned(theiCON.FPopupMenu) THEN
begin
SetForeGroundWindow(IconMgr.hwindow);
GetCursorpos(pt);
TheIcon.FPopupMenu.Popup (pt.x,pt.y);
postMessage(IconMgr.Hwindow ,WM_USER,0,0);
end;
end;
end ;
end else
REsult := DefWindowProc(FHWindow,Msg,Wparam,lparam); end ;
end ;
/////////////////
{TTrayNotifyIcon}
Constructor TTRayNotifyIcon.Create (Aowner : TComponent);
begin
Inherited Create(AOwner);
FIcon := TIcon.Create ;
Ftimer := ttimer.Create (self );
with Ftimer do
begin
Enabled := true ;
Interval := GetDoubleClickTime ;
Ontimer := OnButtonTimer ;
end ;
{keep Default window Icon Handy..}
LoadDefaulticon ;
end;
Destructor TTrayNotifyIcon.Destroy ;
begin
if FIconVisible then SetIconVisible(false );
fIcon.Free ;
Inherited Destroy ;
end ;
function TTrayNotifyIcon.ActiveIconHandle : Thandle ;
begin
if ( Ficon.Handle <>0) then
Result :=FIcon.Handle
else
Result := FDefaultIcon ;
end ;
Procedure TTrayNotifyIcon.LoadDefaultIcon ;
begin
FDefaultIcon := loadIcon(0,IDI_WINLOGO);
end;
procedure TTrayNotifyIcon.Loaded ;
begin
Inherited Loaded ;
if Ficonvisible then
sendTRaymessage(NIM_ADD,NIF_MESSAge OR NIF_Icon or NIF_TIP);
end ;
procedure TTrayNotifyIcon.Notification (AComponent :TComponent ;Operation :TOperation);
begin
Inherited Notification(AComponent,Operation );
if (operation = OPRemove ) and (AComponent = PopupMenu ) then
popupmenu := nil ;
end ;
procedure TTrayNotifyIcon.OnButtonTimer (sender : TObject );
begin
fTimer.Enabled := false ;
if (not FNoshowclick) AND assigned(FOnclick) then
Fonclick (self);
Fnoshowclick := false ;
end ;
procedure TTrayNotifyIcon.SendTrayMessage(Msg : DWORD ;Flags : UINT);
begin
with Tnd do
begin
cbsize :=sizeof (tnd);
StrPlcopy(szTip,pchar(Fhint),sizeof (sztip));
UFlags := flags ;
uID := UINT(self );
Wnd:=Iconmgr.HWindow ;
Ucallbackmessage:=DDGM_TRAYICON ;
HICON := activeIconHandle ;
end ;
shell_Notifyicon(Msg,@Tnd);
end ;
procedure TTrayNotifyIcon.SetHideTask(Value : Boolean );
const showarray : array[boolean] of integer =(sw_showNormal,sw_hide);
begin
if fhidetask <> value then
begin
fhidetask := value ;
if not(csdesigning in componentstate) then
showwindow(Application.handle,showArray[FHideTask]);
end ;end ;
procedure TTrayNotifyIcon.setHint(Value : String );
begin
if Fhint <>Value then
begin
Fhint := Value ;
if FIconvisible then
sendTrayMessage(NIM_MODIFY,NIF_TIP);
end ;
end ;
procedure TTrayNotifyIcon.SetIcon(Value : TIcon );
begin
ficon.Assign (Value);
if FIconvisible then sendTrayMessage(NIM_MODIFY,NIF_ICON);
end ;
procedure TTrayNotifyIcon.setpopupMenu(value : TpopupMenu);begin
FPOPupmenu :=Value ;
if Value <> nil then Value.FreeNotification (self );
end ;
procedure TTrayNotifyIcon.SetIconVisible(Value : Boolean );
const
MsgArray : Array [boolean] of DWORD = ( NIM_DELETE,NIM_ADD);
begin
if ficonvisible<>Value then
begin
ficonvisible :=Value ;
sendtraymessage(msgarray[Value],NIF_MESSAGE or NIF_ICON or NIF_TIP);
end ;end ;
procedure Register;
begin
RegisterComponents('KNTEMP', [TTrayNotifyIcon]);
end;
const TrayMsgStr ='DDG.TrayNotifyIconMsg';initialization
DDGM_TRAYICON := RegisterWindowMessage(TrayMsgStr);
IconMgr := TiconManager.Create ;
finalization
Iconmgr.Free ;
end.
我自己已经搞定了,用了很简单的方法,是从以前的帖子中搜出来的。
SetForegroundWindow(Application.Handle);
Application.ProcessMessages;
PopupMenu1.Popup...就可以了。
多谢各位参与啊!
不过,现在不知道怎么给分了,呵呵。