Q
qwer1234
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我照书上做的,新建一应用程序,实现最小化时,只在系统状态栏显示图标的例子。
这个程序运行正常,能够实现效果,为什么我把这些代码复制到我另一个程序里后,
编译提示:[Error] Player.pas(131): Undeclared identifier: 'Icon'
说Icon未定义,这是为什么?
在下面这个例子里面就是好的啊?请各位大虾指点!!!我应该在我另一个程序里改点什么内容?急!!
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.
这个程序运行正常,能够实现效果,为什么我把这些代码复制到我另一个程序里后,
编译提示:[Error] Player.pas(131): Undeclared identifier: 'Icon'
说Icon未定义,这是为什么?
在下面这个例子里面就是好的啊?请各位大虾指点!!!我应该在我另一个程序里改点什么内容?急!!
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.