qq_26109047 2015-07-14 11:00 采纳率: 0%
浏览 1565

请问下这样的程序怎么写

写一个程序,然后桌面快捷方式指向我的exe,这样双击快捷方式的时候就会启动我的exe,然后由我的exe来启动主程序。同时我的exe也monitor主程序,主程序退出了,我的exe程序也跟着退出
原来的CPP如下
#include "Stdafx.h"
#include "Resource.h"
#include "GamePlaza.h"
#include "PlatformFrame.h"

//////////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(CGamePlazaApp, CWinApp)
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////////////////////////

//构造函数
CGamePlazaApp::CGamePlazaApp()
{
//设置变量
m_pIDispatch=NULL;
m_pCustomOccManager=NULL;

return;

}

//初始函数
BOOL CGamePlazaApp::InitInstance()
{
__super::InitInstance();

#ifndef _DEBUG
#ifndef RELEASE_MANAGER

//存在判断
bool bPlazaExist=false;
CMutex Mutex(FALSE,szPlazaClass,NULL);
if (Mutex.Lock(0)==FALSE) bPlazaExist=true;

//搜索窗口
CWnd * pWndGamePlaza=CWnd::FindWindow(szPlazaClass,NULL);
if (pWndGamePlaza!=NULL) 
{
    //设置变量
    bPlazaExist=true;

    //还原窗口
    if (pWndGamePlaza->IsIconic()) 
    {
        pWndGamePlaza->ShowWindow(SW_RESTORE);
    }

    //激活窗口
    pWndGamePlaza->SetActiveWindow();
    pWndGamePlaza->BringWindowToTop();
    pWndGamePlaza->SetForegroundWindow();
}

//结果处理
if (bPlazaExist==true) return FALSE;

#endif
#endif

//环境配置
AfxOleInit();
AfxInitRichEdit2();
InitCommonControls();
AfxEnableControlContainer();

//_CrtSetBreakAlloc(2089);

//随机种子
srand((DWORD)time(NULL));

//设置表名
SetRegistryKey(szProductKey);

//工作目录
TCHAR szDirectory[MAX_PATH]=TEXT("");
CWHService::GetWorkDirectory(szDirectory,CountArray(szDirectory));

#ifndef _DEBUG
#ifndef RELEASE_MANAGER
//更新判断
if(lstrcmp(AfxGetApp()->m_lpCmdLine,TEXT("UPDATED"))!=0)
{
//目标目录
TCHAR szTargetPath[MAX_PATH]=TEXT("");
_sntprintf(szTargetPath,CountArray(szTargetPath),TEXT("%s\Update.exe"),szDirectory);

    //启动升级
    ShellExecute(NULL,TEXT("open"),szTargetPath,TEXT(""),NULL,true);

    return FALSE;
}

#endif
#endif

//安装目录
CWHRegKey RegInstallPath;
RegInstallPath.OpenRegKey(TEXT(""),true);
RegInstallPath.WriteString(TEXT("InstallPath"),szDirectory);

//加载配置  
m_ParameterGlobal.LoadParameter();
m_GlobalWebLink.LoadPaltformLink();
m_UserInformation.LoadInformation();
m_ExpressionManager.LoadExpression();

//设置目录
SetCurrentDirectory(szDirectory);
m_SkinResourceManager.SetSkinResource(m_ParameterGlobal.m_SkinRenderInfo);

//创建对象
m_pIDispatch=new CImpIDispatch;
m_pCustomOccManager=new CCustomOccManager;
AfxEnableControlContainer(m_pCustomOccManager); 

//创建组件
if (m_FaceItemControlModule.CreateInstance()==false) return false;
if (m_UserOrderParserModule.CreateInstance()==false) return false;
if (m_PlatformResourceModule.CreateInstance()==false) return false;

//用户元素
m_UserItemElement.SetUserOrderParser(m_UserOrderParserModule.GetInterface());
m_UserItemElement.SetFaceItemControl(m_FaceItemControlModule.GetInterface());

//平台资源
m_PlatformResourceModule->LoadDefaultResource(TEXT("PlatformConfig.xml"),GetModuleHandle(NULL));

//变量定义
WNDCLASS WndClasss;
ZeroMemory(&WndClasss,sizeof(WndClasss));

//注册窗口
WndClasss.style=CS_DBLCLKS;
WndClasss.hIcon=LoadIcon(IDR_MAINFRAME);
WndClasss.lpfnWndProc=DefWindowProc;
WndClasss.lpszClassName=szPlazaClass;
WndClasss.hInstance=AfxGetInstanceHandle();
WndClasss.hCursor=LoadStandardCursor(MAKEINTRESOURCE(IDC_ARROW));
if (AfxRegisterClass(&WndClasss)==FALSE) AfxThrowResourceException();

//建立窗口
CPlatformFrame * pPlatformFrame=new CPlatformFrame();
pPlatformFrame->Create(szPlazaClass,szProduct,WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_SYSMENU,CRect(0,0,0,0));

//设置变量
m_pMainWnd=pPlatformFrame;

//声音引擎
m_D3DSound.CreateD3DSound(m_pMainWnd->GetSafeHwnd());

return TRUE;

}

//退出函数
INT CGamePlazaApp::ExitInstance()
{
//保存配置
m_ParameterGlobal.SaveParameter();

//删除对象
SafeDelete(m_pIDispatch);
SafeDelete(m_pCustomOccManager);

return __super::ExitInstance();

}

//////////////////////////////////////////////////////////////////////////////////

//应用程序对象
CGamePlazaApp theApp;

//////////////////////////////////////////////////////////////////////////////////

  • 写回答

2条回答 默认 最新

  • oyljerry 2015-07-14 11:32
    关注

    记得你问过类似的问题。
    启动程序可以用CreateProcess Api。
    检测进程就是开线程周期性遍历当前进程列表,ProcessFirst,ProcessNext

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c