here's the code.
HWND apphwnd; HANDLE handle;
int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param) { DWORD pID; DWORD TpID = GetWindowThreadProcessId(hwnd, &pID); if (TpID == (DWORD)param) { apphwnd=hwnd; return false; } return true; }
HANDLE StartNewProcess(LPCTSTR program, LPCTSTR args) { HANDLE hProcess = NULL; PROCESS_INFORMATION processInfo; STARTUPINFO startupInfo; ::ZeroMemory(&startupInfo, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); if(::CreateProcess(program, (LPTSTR)args, NULL, // process security NULL, // thread security FALSE, // no inheritance 0, // no startup flags NULL, // no special environment NULL, // default startup directory &startupInfo, &processInfo)) { /* success */ Sleep(5000);//wait for the window of exe application created ::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId); hProcess = processInfo.hProcess; } /* success */ return hProcess;//Return HANDLE of process. }
int splash_show_program(char *program) { StartNewProcess(program); ::SetParent(apphwnd,m_hWnd) ::SetWindowLong(apphwnd, GWL_STYLE, WS_VISIBLE); CRect rect; GetClientRect(&rect); ::MoveWindow(apphwnd, rect.left, rect.top,rect.right, rect.bottom, true); }
int splash_terminate_program() { TerminateProcess(handle,0); }
|