// Plan.cpp : main source file for Plan.exe
//
#include "stdafx.h"
#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <string>
#include "resource.h"
#include "MainDlg.h"
CAppModule _Module;
bool IsProcessAlreadyExist(std::string processName)
{
HANDLE handle = NULL;
handle = CreateMutex(NULL,TRUE,CString(processName.c_str()));
if(handle!=NULL)
{
if(GetLastError()==ERROR_ALREADY_EXISTS)
{
return true;
}
}
return false;
}
std::string GetCurrentProcessName()
{
WCHAR wPath[MAX_PATH] = {};
if(0==GetModuleFileName(NULL,wPath,MAX_PATH))
{
return "";
}
int nLen = WideCharToMultiByte(CP_ACP,0,wPath,-1,NULL,0,NULL,NULL);
char* cPath = new char[nLen];
WideCharToMultiByte(CP_ACP,0,wPath,-1,cPath,nLen,NULL,NULL);
std::string strTmp = std::string(cPath);
int pos = strTmp.find_last_of('\\');
std::string curProcessName(strTmp.substr(pos+1,strTmp.length()-pos-1));
delete[] cPath;
return curProcessName;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
std::string processName = GetCurrentProcessName();
if(IsProcessAlreadyExist(processName))
{
MessageBox(NULL,_T("此程序已经启动!"),_T("注意"),MB_OK);
return 0;
}
HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to
// make the EXE free threaded. This means that calls come in on a random RPC thread.
// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));
// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);
AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls
hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));
int nRet = 0;
// BLOCK: Run application
{
CMainDlg dlgMain;
nRet = dlgMain.DoModal();
}
_Module.Term();
::CoUninitialize();
return nRet;
}
WTL简单计划任务程序
5星 · 超过95%的资源 需积分: 0 153 浏览量
2014-11-06
10:21:38
上传
评论
收藏 289KB ZIP 举报
风尘无名
- 粉丝: 113
- 资源: 25
最新资源
- Jetson sdkmanager-2.1.0
- Oracle.ManagedDataAccess.dll4.122.23.1
- 基础知识基础知识基础知识
- Oracle.ManagedDataAccess.dll4.122.21.1
- 基础知识基础知识基础知识
- iris.py
- 火灾自动报警系统设计-毕设.doc
- 模拟退火算法最早由N. Metropolis等人于1953年提出,随后在1983年由S. Kirkpatrick等人成功应用于组
- 深度学习框架,如TensorFlow、PyTorch、Keras等,是机器学习领域中的关键工具 这些框架通常包含大量的预定义函数
- 资源介绍:##Y821FLrR1##PAGE 概述 ##Y821FLrR1##PAGE 是一项独特而富有价值的资源,它可能代表
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈