代码如下
unit Fapp;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellAPI;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure WndProc(var Msg:TMessage);
procedure MyMinimize(Sender:TObject);
public
{ Public declarations }
IconData:TNotifyIconData; end;var
Form1: TForm1;implementation{$R *.dfm}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;
MyMinimize(nil);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_Delete,@IconData);
Application.ProcessMessages;
Application.Terminate;
end;procedure TForm1.WndProc(var Msg:TMessage);
begin
case Msg.Msg of
WM_USER+1:
case Msg.LParam of
WM_LBUTTONDOWN:
begin
Form1.Show;
ShowWindow(Application.Handle,SW_SHOWNORMAL);
end;
end;
end;
inherited;
end;procedure TForm1.MyMinimize(Sender:TObject);
begin
Form1.Hide;
ShowWindow(Application.Handle,SW_Hide);
end;
end.
双击不显示主窗体,根本没有反应,怎么回事?请高手解答
unit Fapp;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellAPI;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure WndProc(var Msg:TMessage);
procedure MyMinimize(Sender:TObject);
public
{ Public declarations }
IconData:TNotifyIconData; end;var
Form1: TForm1;implementation{$R *.dfm}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;
MyMinimize(nil);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_Delete,@IconData);
Application.ProcessMessages;
Application.Terminate;
end;procedure TForm1.WndProc(var Msg:TMessage);
begin
case Msg.Msg of
WM_USER+1:
case Msg.LParam of
WM_LBUTTONDOWN:
begin
Form1.Show;
ShowWindow(Application.Handle,SW_SHOWNORMAL);
end;
end;
end;
inherited;
end;procedure TForm1.MyMinimize(Sender:TObject);
begin
Form1.Hide;
ShowWindow(Application.Handle,SW_Hide);
end;
end.
双击不显示主窗体,根本没有反应,怎么回事?请高手解答
unit Fapp;interfaceuses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
ShellAPI;type
TfrmApp = class(TForm)
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
frmApp: TfrmApp;implementation{$R *.dfm}procedure TfrmApp.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);
FormStyle := fsStayOnTop;
Application.OnMinimize := MyMinimize;
end;procedure TfrmApp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_Delete, @IconData);
end;procedure TfrmApp.WndProc(var Msg: TMessage);
begin
case Msg.Msg of
WM_USER + 1:
case Msg.LParam of
WM_LBUTTONDOWN:
begin
ShowWindow(Handle, SW_SHOWNORMAL);
end;
end;
end;
inherited;
end;procedure TfrmApp.MyMinimize(Sender: TObject);
begin
Shell_NotifyIcon(NIM_ADD, @IconData);end;
end.
你把我的代码考过去试试。
要不你手工设置
FormStyle := fsStayOnTop;
看下面
procedure WndProc(var Msg: TMessage); override;
有个override;