zoukankan      html  css  js  c++  java
  • ShellExecuteEx的使用方法

    关于怎样在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;
     }

  • 相关阅读:
    LeetCode:204. 计数质数
    LeetCode:203. 移除链表元素
    LeetCode:202. 快乐数
    LeetCode:191. 位1的个数
    LeetCode:190. 颠倒二进制位
    LeetCode:189. 旋转数组
    LeetCode:187. 重复的DNA序列
    LeetCode:165. 比较版本号
    LeetCode:164. 最大间距
    LeetCode:155. 最小栈
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4265913.html
Copyright © 2011-2022 走看看