1. 程式人生 > >CreateProcess並隱藏視窗

CreateProcess並隱藏視窗

PROCESS_INFORMATION pi;
STARTUPINFO si;      //隱藏程序視窗
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.cbReserved2 = NULL;
si.lpReserved2 = NULL;
BOOL ret = CreateProcess(NULL,"notepad.exe",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
if(ret)
   {
    CloseHandle(pi.hThread);
    WaitForSingleObject(pi.hProcess,INFINITE);
    GetExitCodeProcess(pi.hProcess,&dwExitCode);
    CloseHandle(pi.hProcess);
    CString tmp;
    tmp.Format("程序關閉",i);
    AfxMessageBox(tmp);
   }