mfrbuaa

关于怎样在c++中启动外部的exe程序,之前看到在百度一搜就看到了:

               ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );

经验证果然能够,一条语句直接就启动了。之后我想在我的代码结束时也把这个exe程序给关闭了,依照网上的做法直接TerminateProcess(HINSTANCE,0)就不行了,參数根本就不能是HINSTANCE类型;然后使用sendMessage(WM_Close,...)也不行,原因应该是我的exe程序根本就没有窗体;最后使用了ShellExecuteEx,总算搞定了。

 

附上代码:

启动:

 SHELLEXECUTEINFO ShExecInfo;

 ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
 ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
 ShExecInfo.hwnd = NULL;
 ShExecInfo.lpVerb = NULL;
 ShExecInfo.lpFile = "xxx.exe"; //can be a file as well
 ShExecInfo.lpParameters = "";
 ShExecInfo.lpDirectory = NULL;
 ShExecInfo.nShow = SW_SHOW;
 ShExecInfo.hInstApp = NULL;
 ShellExecuteEx(&ShExecInfo);

 

关闭:

 if( ShExecInfo.hProcess != NULL)
 {
      TerminateProcess(ShExecInfo.hProcess,0);
      ShExecInfo.hProcess = NULL;
 }

分类:

技术点:

相关文章:

  • 2021-12-16
  • 2021-10-18
  • 2021-12-20
  • 2021-09-14
  • 2021-09-17
  • 2021-10-03
  • 2022-01-01
  • 2021-08-08
猜你喜欢
  • 2021-11-11
  • 2021-11-11
  • 2021-11-11
  • 2021-11-03
  • 2021-08-27
  • 2021-07-30
  • 2021-10-22
相关资源
相似解决方案