簡體   English   中英

如何獲取 firefox 瀏覽器 window 的句柄,以便我可以操作 window

[英]How to get a handle on the firefox browser window so I can manipulate the window

I need to be able to start Firefox from my app and then get a handle to the Firefox browser window in order to move it, resize it, etc. In the app, Firefox is started using CreateProcessAsUser() .

問題是,Firefox 默認使用啟動器進程

在 Firefox 的 Windows 版本中,啟動器進程是用戶運行 Firefox 時啟動的初始進程。 其唯一目的是在暫停的 state 中創建瀏覽器進程,配置瀏覽器進程,恢復瀏覽器進程,然后將 GUI 前台移交給瀏覽器。 一旦啟動器進程完成了這個目標,它就會退出。

因為 Firefox 使用啟動器進程啟動瀏覽器 window,所以CreateProcessAsUser()返回的 PID 不是瀏覽器 window 的 PID。 所以我不能使用EnumWindows()並匹配 PID。 I know that the Window class type for the browser window is MozillaWindowClass , but it's possible there will be multiple windows of this type in my context.

如何在瀏覽器 window 上獲取句柄以便以編程方式對其進行操作?

Firefox 不提供 API 以獲得您想要的。

您從CreateProcessAsUser()獲得了啟動器的 PID。 在您關閉CreateProcessAsUser()返回的HANDLE之前,該 PID 將保持有效並且不會被回收。 這意味着,您可以枚舉正在運行的進程,直到找到其父 PID 為啟動器 PID 1的進程。 然后,您可以枚舉 windows 尋找屬於該子 PID 的一個。

1 :或者,當您創建啟動器進程時,將其分配給作業 Object ,然后您可以監視JOB_OBJECT_MSG_NEW_PROCESS消息,指示新的子進程已添加到作業中。 然后您將獲得新進程的 PID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM