在程序中重启自己的一种方法

文章作者 100test 发表时间 2007:08:06 12:56:50
来源 100Test.Com百考试题网


在工程.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.
  }


  主窗口的单元头文件(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().
  }

src="/ncre2/js/wxgg.js">

相关文章


高质量C _C编程指南(二)
用Winsock实现语音全双工通信
在程序中重启自己的一种方法
用VC6.0实现快捷方式中的查找目标功能
程序开发:目前主流开发技术的分析和总结
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛