服务程序

1 Close All

2 New->Service Application

3 NewForm按纽,产生Form2
  Unit2.h,Unit2.cpp

4 在Form2上    
   TImageList *ImageList1;
   TPopupMenu *PopupMenu1;
   TTrayIcon *TrayIcon1;

5 处理好图标

6 form2上加2个弹出按纽TMenuItem *N1; TMenuItem *N2;
  void __fastcall TForm2::N1Click(TObject *Sender)
  {
  ShowMerssage("显示");
  TrayIcon1->Restore();
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm2::N2Click(TObject *Sender)
 {
  TrayIcon1->Minimize();
 }
  void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
 {
  Action=caNone;
  TrayIcon1->Minimize();
  }

7  Unit1.cpp
   #include "Unit2.h"

8 __fastcall TService1::TService1(TComponent* Owner)
 : TService(Owner)
{

}
中加Interactive=true;

9 Unit1中双击Service1的TService::OnStart事件
 
///
#ifndef Unit1H
#define Unit1H
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <SvcMgr.hpp>
#include <vcl.h>
//---------------------------------------------------------------------------
class TService1 : public TService
{
__published:
        void __fastcall ServiceStart(TService *Sender, bool &Started);
public:
 __fastcall TService1(TComponent* Owner);
 TServiceController __fastcall GetServiceController(void);

 friend void __stdcall ServiceController(unsigned CtrlCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TService1 *Service1;
//---------------------------------------------------------------------------
#endif


#include "Unit1.h"
#include "Unit2.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TService1 *Service1;
//---------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner)
 : TService(Owner)
{
Interactive=true;
}
//---------------------------------------------------------------------------
TServiceController __fastcall TService1::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
 Service1->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceStart(TService *Sender, bool &Started)
{
  Form2->Show();
  Form2->TrayIcon1->Visible=true;
  Form2->TrayIcon1->Minimize();
}
//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "trayicon.h"
#include <ImgList.hpp>
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published:
        TImageList *ImageList1;
        TPopupMenu *PopupMenu1;
        TTrayIcon *TrayIcon1;
        TMenuItem *N1;
        TMenuItem *N2;
        void __fastcall N1Click(TObject *Sender);
        void __fastcall N2Click(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
public: 
        __fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N1Click(TObject *Sender)
{
ShowMessage("显示");
TrayIcon1->Restore();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N2Click(TObject *Sender)
{
 TrayIcon1->Minimize();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Action=caNone;
TrayIcon1->Minimize();
}
//---------------------------------------------------------------------------
2;
//---------------------------------------------------------------------------
#endif
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值