Re: Stop and run an application? by Denis
Denis
Sun May 09 10:41:35 CDT 2004
Hi again,
Another approach to find the window of the process if you don't know the
window class name but have created the process from your application:
1. After creating of process you have the processId.
2. Then you can iterate all windows in the system and retriving the
processId of the owning process and send
WM_CLOSE to process with the same Id as you obtained during creation of
process.
The code would look like following:
typedef struct {
DWORD dwProcessId;
HWND hWnd;
}my_procinfo_type;
BOOL CALLBACK EnumWindowsProc(HWND hWnd, DWORD lParam)
{
DWORD dwProcessId = 0;
my_procinfo_type *pi = (my_procinfo_type *)lParam;
if (GetWindowThreadProcessId(hWnd, &dwProcessId))
{
if (pi->dwProcessId == dwProcessId)
{
pi->hWnd = hWnd;
return FALSE;
}
}
return TRUE; // continue
}
void MyTerminateProcess(DWORD dwProcessId ) // dwProcessId is obtained from
CreateProcess
{
my_procinfo_type pi;
pi.hWnd = NULL;
pi.dwProcessId = dwProcessId;
EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)&pi);
if (pi.hWnd)
PostMessage(pi.hWnd, WM_CLOSE, 0,0);
...
// wait 5 second for process
// then call TerminateProcess.
....
}
Regards,
Denis
"Kimo" <anonymous@discussions.microsoft.com> schrieb im Newsbeitrag
news:5DB2997E-0B96-43D6-8D81-A62166FD9B31@microsoft.com...
> Hi,
> How can I stop and run an application programatically?
> Thanks,
> Kimo