?? zztg.cpp
字號:
// zztg.cpp : 定義應用程序的類行為。
//
#include "stdafx.h"
#include "zztg.h"
#include "zztgDlg.h"
#include "zzxs_Thread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CzztgApp
BEGIN_MESSAGE_MAP(CzztgApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CzztgApp 構造
CzztgApp::CzztgApp()
{
// TODO: 在此處添加構造代碼,
// 將所有重要的初始化放置在 InitInstance 中
}
// 唯一的一個 CzztgApp 對象
CzztgApp theApp;
// CzztgApp 初始化
BOOL CzztgApp::InitInstance()
{
// 如果一個運行在 Windows XP 上的應用程序清單指定要
// 使用 ComCtl32.dll 版本 6 或更高版本來啟用可視化方式,
//則需要 InitCommonControls()。否則,將無法創(chuàng)建窗口。
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
CNTServiceParam param;//建立NTService類對象事例;
param.Parse();
CString strServiceName="ZZxsSMS";
if(!param.HadParam()){
CzzxsServices service;
int iCode = CNTService::Run(&service,strServiceName);
if(iCode!=ERROR_OK){
AfxMessageBox("運行失敗\n");
}
}
else{
CString strParam = param.GetAt(0);
strParam.MakeLower();
if(strParam=="install"){
TCHAR path[MAX_PATH];
::GetModuleFileName(NULL,path,MAX_PATH);
SERV_INFO info;
ZeroMemory(&info,sizeof(info));
info.enStartType = Manual;
strcat(info.tcServiceDesc,"自寫短信服務程序");
strcat(info.tcServiceDisplayName,"自寫短信服務程序");
strcat(info.tcServicePath,path);
int iCode = ::ServiceInstall(strServiceName,info);
CString strMsg;
if(iCode!=ERROR_OK)
strMsg.Format("安裝失敗,錯誤代碼:%d\n",iCode);
else
strMsg.Format("安裝成功,服務名稱: %s\n",info.tcServiceDisplayName);
AfxMessageBox(strMsg);
}
else if(strParam=="uninstall"){
int iCode=::ServiceUninstall(strServiceName);
CString strMsg;
if(iCode!=ERROR_OK)
strMsg.Format("卸載失敗,錯誤代碼:%d\n",iCode);
else
strMsg.Format("卸載成功\n");
AfxMessageBox(strMsg);
}
else if(strParam=="startapp")
{
CzztgDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO:在此放置處理何時用“確定”來關閉
//對話框的代碼
}
else if (nResponse == IDCANCEL)
{
// TODO:在此放置處理何時用“取消”來關閉
//對話框的代碼
}
}
else
AfxMessageBox(_T("參數錯誤,只支持-install,-uninstall\n"));
}
// 由于對話框已關閉,所以將返回 FALSE 以便退出應用程序,
// 而不是啟動應用程序的消息泵。
return FALSE;
}
void CzzxsServices::OnStart(){
m_pThread = ::AfxBeginThread(RUNTIME_CLASS(zzxs_Thread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
m_pThread->ResumeThread();
}
void CzzxsServices::OnStop(){
TerminateThread(m_pThread->m_hThread,0xdead);
}
void CzzxsServices::OnPause(){
if(this->m_pThread)this->m_pThread->SuspendThread();
}
void CzzxsServices::OnContinue(){
if(this->m_pThread)this->m_pThread->ResumeThread();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -