浪
浪人情哥
Unregistered / Unconfirmed
GUEST, unregistred user!
给你个例子算了,没有时间给你调了
program Project1;
uses
SvcMgr,forms,
Unit1 in 'Unit1.pas' {TestService: TService},
Unit2 in 'Unit2.pas' {Form2};
{$R *.RES}
begin
forms.Application.Initialize;
forms.Application.CreateForm(TForm2, Form2);
svcmgr.Application.Initialize;
svcmgr.Application.CreateForm(TTestService, TestService);
svcmgr.Application.Run;
forms.Application.Run;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,forms,shellapi;
type
TTestService = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
procedure AddTray;
end;
var
TestService: TTestService;
implementation
uses unit2;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
TestService.Controller(CtrlCode);
end;
procedure TTestService.AddTray;
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := form2.Handle; // 主窗口句柄
nid.uID := 1215; // 内部标识,可设为任意数
nid.hIcon := forms.Application.Icon.Handle; // 要加入的图标句柄,可任意指定
nid.szTip := 'Test'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效
while not Shell_NotifyIcon(NIM_ADD, @nid) do begin
//Application.MessageBox('初始化应用服务器图标出错!','错误',MB_ICONERROR);
//Application.Terminate;
sleep(1000);
end;
end;
function TTestService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TTestService.ServiceStart(Sender: TService;
var Started: Boolean);
begin
AddTray;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
MY_MESSAGE= WM_USER + 110;
type
TForm2 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
Button1: TButton;
private
{ Private declarations }
procedure OnIconNotify(var Message: TMessage); message my_Message;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.OnIconNotify(var Message: TMessage);
var
curPoint: TPoint;
begin
if message.Msg=my_message then
begin
if Message.LParam = WM_RBUTTONDOWN then
begin
SetForegroundWindow(Handle);
GetCursorPos(curPoint);
//PopupMenu4.Popup(curPoint.X, curPoint.Y);
end;
if Message.LParam =WM_LBUTTONDBLCLK then
begin
show;//btnOPen.Click;
end;
end
else
show;//visble1Click(nil);
end;
end.
program Project1;
uses
SvcMgr,forms,
Unit1 in 'Unit1.pas' {TestService: TService},
Unit2 in 'Unit2.pas' {Form2};
{$R *.RES}
begin
forms.Application.Initialize;
forms.Application.CreateForm(TForm2, Form2);
svcmgr.Application.Initialize;
svcmgr.Application.CreateForm(TTestService, TestService);
svcmgr.Application.Run;
forms.Application.Run;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,forms,shellapi;
type
TTestService = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
procedure AddTray;
end;
var
TestService: TTestService;
implementation
uses unit2;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
TestService.Controller(CtrlCode);
end;
procedure TTestService.AddTray;
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := form2.Handle; // 主窗口句柄
nid.uID := 1215; // 内部标识,可设为任意数
nid.hIcon := forms.Application.Icon.Handle; // 要加入的图标句柄,可任意指定
nid.szTip := 'Test'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效
while not Shell_NotifyIcon(NIM_ADD, @nid) do begin
//Application.MessageBox('初始化应用服务器图标出错!','错误',MB_ICONERROR);
//Application.Terminate;
sleep(1000);
end;
end;
function TTestService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TTestService.ServiceStart(Sender: TService;
var Started: Boolean);
begin
AddTray;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
MY_MESSAGE= WM_USER + 110;
type
TForm2 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
Button1: TButton;
private
{ Private declarations }
procedure OnIconNotify(var Message: TMessage); message my_Message;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.OnIconNotify(var Message: TMessage);
var
curPoint: TPoint;
begin
if message.Msg=my_message then
begin
if Message.LParam = WM_RBUTTONDOWN then
begin
SetForegroundWindow(Handle);
GetCursorPos(curPoint);
//PopupMenu4.Popup(curPoint.X, curPoint.Y);
end;
if Message.LParam =WM_LBUTTONDBLCLK then
begin
show;//btnOPen.Click;
end;
end
else
show;//visble1Click(nil);
end;
end.