2

初始说明,我不是 ac# 程序员,但我已经为 chrome 和 firefox 开发了插件/扩展,并且我需要 Internet Explorer 的第三个扩展以用于与工作相关的项目。

我正在尝试从 IE 中的 BHO 扩展访问 Internet Explorer 实例。我一直在使用以下资源:

所以,我有基本的插件工作,并通过在窗口完成加载时注入一个 javascript 警报框来测试它。

我的插件最终将不得不管理两个选项卡(一个充当主机,另一个充当从属),并且提到的最后一个链接处理它,但它需要浏览器的 HWND 句柄,我不知道如何获得它.

看起来它可能在WebBrowser成员之下,.Parent但我不知道我需要将它转换为哪个类才能获得 IE 句柄。

4

1 回答 1

1

因此,要获取任何浏览器甚至任何在机器上运行的进程的句柄,您可以使用以下 FindWindow 方法:

User32.dll

通过以下方式在您的课程中包含对它的引用:

    // Find by class name and window name
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    // Find window name only
    [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

你可以在你的班级里给他们打电话,如下所示:

    public FindMyWindow(string classname, string windowName)
    {
        IntPtr hWnd = FindWindow(classname, null);
        // Or do
        hWnd = FindWindowByCaption(IntPtr.Zero, windowName);
    }

您可以使用

间谍++

如果需要,它会随 Visual Studio 2010 一起找到类名。

于 2012-06-19T01:39:09.740 回答