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.
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.