【发布时间】:2014-02-24 14:55:39
【问题描述】:
我有一个外部应用程序,我希望它在浏览器窗口顶部显示一些信息。我的引导扩展需要将浏览器窗口句柄(本机 HWND)以及有关窗口的其他一些有用信息传递给我的应用程序。我能够在它们之间进行通信,唯一缺少的是获取 Firefox 窗口的本机 HWND 的方法。
我阅读了很多关于它的内容,虽然我相信这是可能的,但我找不到可行的解决方案。到目前为止,这是我尝试过的:
这个应该给我nsIBaseWindow,所以我可以得到nsIBaseWindow.nativeHandle或nsIBaseWindow.ParentNativeWindow,但没有成功:
var window = SomeDOMWindow; // Informative
var baseWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIXULWindow)
.docShell
.QueryInterface(Components.interfaces.nsIBaseWindow);
上面的代码在论坛上广泛传播,但我无法让它为我工作。
另一个似乎不太准确,因为它根据窗口的类和标题获取 HWND,这可能会导致错误的结果:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("user32.dll");
var fww = lib.declare("FindWindowW", ctypes.winapi_abi,
ctypes.voidptr_t, ctypes.jschar.ptr, ctypes.jschar.ptr);
var sfw = lib.declare("SetForegroundWindow", ctypes.winapi_abi,
ctypes.int32_t, ctypes.voidptr_t);
var hwnd = fww("MozillaWindowClass", document.title);
setTimeout(function() {
sfw(hwnd);
lib.close();
}, 3000);
任何帮助将不胜感激。
【问题讨论】:
标签: firefox-addon xul xpcom jsctypes