我使用此代码启动网络浏览器,然后终止它。然而,在启动 webbrowser 并使其成为活动窗口之后,它会在后台捕获窗口(启动浏览器的应用程序)并终止它。所以我希望它终止前台(网络浏览器)中的窗口。
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\iexplore.exe";
ShExecInfo.lpParameters = "http://www.google.se";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWMAXIMIZED;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,10);
DWORD Pid = GetCurrentProcessId();
HANDLE h = OpenProcess(PROCESS_TERMINATE, false, Pid);
TerminateProcess(h, 1);
CloseHandle(h);
我想问题是 GetCurrentProcessId() 给了我正在运行的应用程序的 id,而不是新打开的 webbrowser。这是为什么?