1.WinExeC
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);
下面是影藏打開 www.88181.com,然後關閉
[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);
- }
- }