当前位置:天才代写 > tutorial > C语言/C++ 教程 > 在措施中重启本身的一种要领

在措施中重启本身的一种要领

2017-11-05 08:00 星期日 所属: C语言/C++ 教程 浏览:659

副标题#e#

在工程.cpp文件(Project1.cpp)中插手:

#include "Unit1.h"
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
   try
   {
     Application->Initialize();
     Application->CreateForm(__classid(TfrmMain), &frmMain);
     Application->Run();
   }
   catch (Exception &exception)
   {
     Application->ShowException(&exception);
   }
   catch (...)
   {
     try
     {
       throw Exception("");
     }
     catch (Exception &exception)
     {
       Application->ShowException(&exception);
     }
   }
   if(g_bIsRunAgain)
   {
     AnsiString strPath;
     STARTUPINFO StartInfo;
     PROCESS_INFORMATION procStruct;
     memset(&StartInfo, 0, sizeof(STARTUPINFO));
     StartInfo.cb = sizeof(STARTUPINFO);
     strPath = Application->ExeName;
     if(!::CreateProcess(
         (LPCTSTR) strPath.c_str(),
         NULL,
         NULL,
         NULL,
         FALSE,
         NORMAL_PRIORITY_CLASS,
         NULL,
         NULL,
         &StartInfo,
         &procStruct))
       return 0;
   }
   return 0;
}


#p#副标题#e#

主窗口的单位头文件(Unit1.h)中插手:

extern bool g_bIsRunAgain;

主窗口的单位.cpp(Unit1.cpp)中插手:

bool g_bIsRunAgain = false;
//----------------------------------------------------------------------------
// 封锁措施
void __fastcall TfrmMain::btnCloseClick(TObject *Sender)
{
   Close();
}
//----------------------------------------------------------------------------
// 重启应用措施
void __fastcall TfrmMain::btnReExcuteClick(TObject *Sender)
{
   g_bIsRunAgain = true;
   Close();
}

 

    关键字:

天才代写-代写联系方式