非高手不能解决的图标问题!(35分)

E

eryu

Unregistered / Unconfirmed
GUEST, unregistred user!
程序最小化时缩为系统状态栏图标的程序,现有两个问题:
1、右键单击状态栏上的程序图标,还原为窗口,但状态栏上的图标没有消失,怎样让它在还
原为窗口时,图标消失?
2、关闭程序后,状态栏上的图标也没有自动消失,把鼠标移到图标上后,图标才消失,怎样
在程序关闭后,图标自动消失?
以下是我这部分的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI;
const
WM_BARICON=WM_USER+200;
type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMSysComand(var message: TMessage);
message WM_SYSCOMMAND;
procedure WMBarIcon(var message: TMessage);
message WM_BARICON;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.WMSysComand(var message: TMessage);
var
lpData: PNotifyIconData;
begin
if Message.WParam = SC_ICON then
begin
lpData:=new(PNotifyIconDataA);
lpData.cbSize:=88;
lpData.Wnd:=form1.Handle;
lpData.hIcon:=form1.Icon.Handle;
lpData.uCallbackMessage:=WM_BARICON;
lpData.uID:=0;
lpData.szTip:='Samples';
lpData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
Form1.Visible:=false;
end
else
begin
DefWindowProc(Form1.Handle,Message.Msg,Message.WParam,Message.LParam);
end;
end;

procedure tform1.WMBarIcon(var Message: TMessage);
var
lpData: PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) then
begin
lpData:=new(PNotifyIconDataA);
lpData.cbSize:=88;
lpData.Wnd:=form1.Handle;
lpData.hIcon:=form1.Icon.Handle;
lpData.uCallbackMessage:=WM_BARICON;
lpData.uID:=0;
lpData.szTip:='Samples';
lpData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon(NIM_ADD,lpData);
dispose(lpData);
Form1.Visible:=true;
end;
end;

end.
 
D

delphiland

Unregistered / Unconfirmed
GUEST, unregistred user!
第二个procedure 是否应该是这样:
procedure tform1.WMBarIcon(var Message: TMessage);
var
lpData: PNotifyIconData;
begin
if (Message.LParam = WM_LBUTTONDOWN) then
begin
....
Shell_NotifyIcon(NIM_DELETE,lpData);
....
===============================================
我一般这样用:
CONST CM_TRAYICON = CM_BASE + 84;
type
TForm1 = class(TForm)
private
{ Private declarations }
IconData:TNotifyIconData;
procedure OnIconNotify(var Msg: TMessage);message CM_TRAYICON;
public
{ Public declarations }
end;

procedure TMainFM.FormCreate(Sender: TObject);
begin
with IconDatado
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
hIcon := LoadIcon(hInstance,'MainICON');
StrPLCopy(szTip, GetShortHint('数据处理程序运行中...'), SizeOf(szTip) - 1);
uCallbackMessage := CM_TRAYICON;
uID := 0;
end;
Shell_NotifyIcon(NIM_ADD, @IconData);
//需要去掉时就去掉
procedure TMainFM.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
//响应消息
procedure TMainFM.OnIconNotify(var Msg: TMessage);
Var
MPoint:TPoint;
begin
Case Msg.LParam of
WM_LBUTTONDBLCLK:
begin
if NOT Visible then
ZoomEffect(Self, zaMaximize);
Visible := True;
Application.Restore;
Application.BringToFront;
end;
WM_RBUTTONUP:
begin
GetCursorPos(MPoint);
PopMenu.Popup(MPoint.x,MPoint.y);
end;
end;
end;
//很方便,也不用控件,再用个Timer可以做成动画式的
 
E

eryu

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 
I

Imfish

Unregistered / Unconfirmed
GUEST, unregistred user!
To 第二个问题:
关闭程序时用close.你试一下!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
629
import
I
S
回复
0
查看
815
SUNSTONE的Delphi笔记
S
顶部