3

我创建了一个 c++ 程序,它还安装了一个 firefox 扩展。因此,要使此扩展程序正常工作,他需要重新启动 Firefox。

那么,当用户使用它时,我如何要求重新启动 Firefox 呢?

4

2 回答 2

1

This kind of looks like a duplicate to this question: winapi - How can I get a process handle by its name in C++. Essentially, what you'd be looking to do is "find" the process "firefox.exe" (in place of "target.exe") and if finding it is successful, you put up a warning dialogue box to close firefox and re-open. If not, you just continue with the install or whatever. Hope this helped!

于 2012-06-04T14:45:31.487 回答
0

Find the main window of Firefox using its caption. I guess Firefox appends the title of the current page to the caption of the main window, so FindWindow is not enough. Try to enumerate top-level windows using EnumWindows, and find the one containing "Mozilla Firefox" in the caption. If you have the window handle, send a WM_CLOSE message to it (use PostMessage which waits for the target window to process the message), and wait for it to disappear. You may get a popup, find and close it the same way. If the main Firefox window is still open after a few seconds (try to find it repeatedly), you may call TerminateProcess (you will need GetWindowThreadProcessId and OpenProcess for this). When the window is closed, restart Firefox by calling CreateProcess. (There are lots of examples for all these API functions on the Web.)

于 2012-06-04T14:46:33.363 回答