I want to send wm_close to another process that I want to end this process with safely.
int _tmain(int argc, _TCHAR* argv[]) { DWORD SetOfPID; SetOfPID = GetProcId(_T("abc.exe")); //this will return pid HANDLE h = OpenProcess(PROCESS_ALL_ACCESS,false, SetOfPID); HWND hwnd = ::GetTopWindow(NULL); while(hwnd) { DWORD pid; DWORD dwThreadId = ::GetWindowThreadProcessId(hwnd, &pid); if(pid == SetOfPID) { break; } hwnd = ::GetNextWindow(hwnd, GW_HWNDNEXT); } //DestroyWindow(hwnd); bool temp = IsWindow(hwnd); **//this gives true** LRESULT res = ::SendMessage(hwnd, WM_CLOSE, NULL, NULL); DWORD err = GetLastError(); **//this gives 6** CloseHandle(hwnd); CloseHandle(h); return 0; }
this piece of code looks good, but the target process does not end, can someone help me?
source share