C++调用可执行程序

WinExec(strPath.c_str(), SW_SHOW) ;

关闭:

HWND dc = FindWindow(0, "无标题 - 记事本 ");
  CloseWindow(dc); 
如果不行的话,按ctr+del+alt看记事本的标题是什么??改了它

2.

HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd);

下面是影藏打开 ,然后关闭

[cpp]

//声明结构体    SHELLEXECUTEINFO ShExecInfo;   //创建    void CBaseDialogDlg::OnButton1()    {       ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);       ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;       ShExecInfo.hwnd = NULL;       ShExecInfo.lpVerb = NULL;       ShExecInfo.lpFile = "calc.exe"//can be a file as well        ShExecInfo.lpParameters = "";        ShExecInfo.lpDirectory = NULL;       ShExecInfo.nShow = SW_SHOW;       ShExecInfo.hInstApp = NULL;        ShellExecuteEx(&ShExecInfo);   }      //关闭    void CBaseDialogDlg::OnButton2()    {       if( ShExecInfo.hProcess != NULL)       {               TerminateProcess(ShExecInfo.hProcess,0);           ShExecInfo.hProcess = NULL;       }   }  

3.

CreateProcess

下面是用CreateProcess打开一个进程,然后关闭那个进程

[cpp]

static   DWORD   dwProcessId=0;   //你启动的另一个程序的进程ID      void   __fastcall   TForm1::Button1Click(TObject   *Sender)     {             STARTUPINFO   si;             PROCESS_INFORMATION   pi;                memset(&si,   0,   sizeof(si));             si.cb   =   sizeof(STARTUPINFO);             if   (CreateProcess(NULL, "notepad.exe ",NULL,                     NULL,FALSE,0,NULL,NULL,&si,&pi))   {                     dwProcessId   =   pi.dwProcessId;                     CloseHandle(pi.hProcess);                     CloseHandle(pi.hThread);             }     }        void   __fastcall   TForm1::Button2Click(TObject   *Sender)     {             HANDLE   hProcess;                hProcess   =   OpenProcess(PROCESS_ALL_ACCESS,                     FALSE,   dwProcessId);             if   (hProcess   !=   NULL)   {                     TerminateProcess(hProcess,   0);                     CloseHandle(hProcess);             }     }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyzxgp.html