myservicewinservice.h

来自「Visual_C++.NET实用编程百例」· C头文件 代码 · 共 100 行

H
100
字号
#pragma once

using namespace System;
using namespace System::Collections;
using namespace System::ServiceProcess;
using namespace System::ComponentModel;


namespace MyService
{
	/// <summary> 
	/// MyServiceWinService 摘要
	/// </summary>
	///
	/// 警告: 如果您更改该类的名称,则需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	public __gc class MyServiceWinService : public System::ServiceProcess::ServiceBase 
	{
	public:
		MyServiceWinService()
		{
			InitializeComponent();    
		}
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		void Dispose(bool disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
		
	protected:
		/// <summary>
		/// 设置具体的操作,以便服务可以执行它的工作。
		/// </summary>
		void OnStart(String* args[])
		{
			// TODO: 在此处添加代码以启动服务。
		}
		
		/// <summary>
		/// 停止此服务。
		/// </summary>
		void OnStop()
		{     
			// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
		}
	private: System::Windows::Forms::Timer *  timer1;
	private: System::ComponentModel::IContainer *  components;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>


		/// <summary> 
		/// 设计器支持所需的方法 - 不要用代码编辑器
		///修改此方法的内容。
		/// </summary>	
		void InitializeComponent(void)
		{
			this->components = new System::ComponentModel::Container();
			this->timer1 = new System::Windows::Forms::Timer(this->components);
			// 
			// timer1
			// 
			this->timer1->Tick += new System::EventHandler(this, timer1_Tick);
			// 
			// MyServiceWinService
			// 
			this->CanPauseAndContinue = true;
			this->ServiceName = S"MyServiceWinService";

		}		
	private: System::Void timer1_Tick(System::Object *  sender, System::EventArgs *  e)
			 {
				 DateTime *t;
				 if(t->get_Minute()==0 || t->get_Second ()==0)
				 {
					 String *str;
					 String *temp=t->get_Hour().ToString ();
					 str->Concat(S"现在是");
					 str->Concat (temp);
					 str->Concat (S"点整");
					 System::Windows::Forms::MessageBox::Show(str);
				 }

			 }

	};
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?