S
shijiesun
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,shellapi, Menus, ExtDlgs;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure WndProc(var Msg: TMessage); override;
procedure MyMinimize(Sender:TObject);
public
{ Public declarations }
IconData: TNotifyIconData;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WndProc(var Msg:TMessage);
var
p:TPoint;
begin
case Msg.Msg of
WM_USER+1:
case Msg.LParam of
WM_RBUTTONDOWN: //右键
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
WM_LBUTTONDBLCLK: //双击
begin
Form1.Show;
ShowWindow(Application.Handle,SW_SHOWNORMAL);
end;
end;
end;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IconData.cbSize := sizeof(IconData);
IconData.Wnd :=Handle;
IconData.uID := 100;
IconData.uFlags :=NIF_MESSAGE+NIF_ICON+NIF_TIP;
IconData.uCallbackMessage := WM_USER+1;
IconData.hIcon := Application.Icon.Handle;
StrPCopy(IconData.szTip,Application.Title);
Shell_notifyIcon(NIM_ADD, @IconData);
Application.OnMinimize:= MyMinimize;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE,@IconData);
Application.ProcessMessages;
Application.Terminate;
end;
procedure TForm1.MyMinimize(Sender: TObject);
begin
Form1.hide;
ShowWindow(Application.Handle,SW_hide);
end;
end.
编译后显示:
[Hint] Unit1.pas(17): Overriding virtual method 'TForm1.WndProc' has lower visibility (private) than base class 'TForm' (protected)
编译后可以生成exe应用程序,但是鼠标点击托盘图标无效,请问怎么回事?
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,shellapi, Menus, ExtDlgs;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure WndProc(var Msg: TMessage); override;
procedure MyMinimize(Sender:TObject);
public
{ Public declarations }
IconData: TNotifyIconData;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WndProc(var Msg:TMessage);
var
p:TPoint;
begin
case Msg.Msg of
WM_USER+1:
case Msg.LParam of
WM_RBUTTONDOWN: //右键
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X,p.Y);
end;
WM_LBUTTONDBLCLK: //双击
begin
Form1.Show;
ShowWindow(Application.Handle,SW_SHOWNORMAL);
end;
end;
end;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IconData.cbSize := sizeof(IconData);
IconData.Wnd :=Handle;
IconData.uID := 100;
IconData.uFlags :=NIF_MESSAGE+NIF_ICON+NIF_TIP;
IconData.uCallbackMessage := WM_USER+1;
IconData.hIcon := Application.Icon.Handle;
StrPCopy(IconData.szTip,Application.Title);
Shell_notifyIcon(NIM_ADD, @IconData);
Application.OnMinimize:= MyMinimize;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE,@IconData);
Application.ProcessMessages;
Application.Terminate;
end;
procedure TForm1.MyMinimize(Sender: TObject);
begin
Form1.hide;
ShowWindow(Application.Handle,SW_hide);
end;
end.
编译后显示:
[Hint] Unit1.pas(17): Overriding virtual method 'TForm1.WndProc' has lower visibility (private) than base class 'TForm' (protected)
编译后可以生成exe应用程序,但是鼠标点击托盘图标无效,请问怎么回事?