6

Outlook 的 Dynamics 插件通过 Internet Explorer 嵌入式窗口显示内容。我正在尝试找到一种方法来获取该嵌入式窗口的 SHDocVw.InternetExplorer COM 对象。我们的应用程序独立运行(它不是 Outlook 或 IE 插件),我们根本无法控制嵌入式 IE 窗口的创建。

当我使用:

Dim SWs As SHDocVw.ShellWindows
Set SWs = New SHDocVw.ShellWindows

SWs 集合不包含对 Outlook 中嵌入式浏览器的引用(尽管我确实得到了对常规浏览器窗口的引用)。

使用 Spy++,我看到嵌入式 Outlook 窗口的以下窗口层次结构:

Window "xxxxxx" WindowsForms10.Window.8.app.0.5c39d4_r64_ad2
  - "" Shell Embedding
    - "" Shell DocObject View
      - "" Internet Explorer_Server

层次结构中的最后两个窗口(Shell DocObject View 和 Internet Explorer_Server)与正在运行的 Internet Explorer 实例中的嵌入式查看器完全相同。

似乎必须有某种方法来获得对这些嵌入式浏览器的 COM 引用 - 任何帮助或想法将不胜感激。

4

2 回答 2

5

请参阅知识库文章 249232。您可以使用辅助功能IHTMLDocument2Internet Explorer_Server窗口中获取指针。它不漂亮,如果您在与目标进程不同的完整性级别上运行,它将无法工作。

根据您的操作,您可能会破坏目标应用程序的稳定性,因此请小心。并注意编组。

于 2012-06-22T22:15:24.077 回答
1

以下是使用 Hwnd 获取 HTMLDocument 的方法:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    using mshtml;

    namespace HookBrowser
    {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region API CALLS

        [DllImport("user32.dll", EntryPoint = "GetClassNameA")]
        public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);

        /*delegate to handle EnumChildWindows*/
        public delegate int EnumProc(IntPtr hWnd, ref IntPtr lParam);

        [DllImport("user32.dll")]
        public static extern int EnumChildWindows(IntPtr hWndParent, EnumProc lpEnumFunc, ref  IntPtr lParam);
        [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageA")]
        public static extern int RegisterWindowMessage(string lpString);
        [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")]
        public static extern int SendMessageTimeout(IntPtr hwnd, int msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult);
        [DllImport("OLEACC.dll")]
        public static extern int ObjectFromLresult(int lResult, ref Guid riid, int wParam, ref IHTMLDocument2 ppvObject);
        public const int SMTO_ABORTIFHUNG = 0x2;
        public Guid IID_IHTMLDocument = new Guid("626FC520-A41E-11CF-A731-00A0C9082637");

        #endregion

        public IHTMLDocument2 document;

        private void button1_Click(object sender, EventArgs e)
        {
            document = documentFromDOM();
            /// check that we have hold of the IHTMLDocument2...
            if (!(bool)(document == null))
            {
                this.Text = document.url;
            }
        }

        private IHTMLDocument2 documentFromDOM()
        {
            Process[] processes = Process.GetProcessesByName("iexplore");
            if (processes.Length > 0)
            {
                IntPtr hWnd = processes[0].MainWindowHandle;
                int lngMsg = 0;
                int lRes;

                EnumProc proc = new EnumProc(EnumWindows);
                EnumChildWindows(hWnd, proc, ref hWnd);
                if (!hWnd.Equals(IntPtr.Zero))
                {
                    lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT");
                    if (lngMsg != 0)
                    {
                        SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes);
                        if (!(bool)(lRes == 0))
                        {
                            int hr = ObjectFromLresult(lRes, ref IID_IHTMLDocument, 0, ref document);
                            if ((bool)(document == null))
                            {
                                MessageBox.Show("NoLDocument Found!", "Warning");
                            }
                        }
                    }
                }
            }
            return document;
        }

        private int EnumWindows(IntPtr hWnd, ref IntPtr lParam)
        {
            int retVal = 1;
            StringBuilder classname = new StringBuilder(128);
            GetClassName(hWnd, classname, classname.Capacity);
            /// check if the instance we have found is Internet Explorer_Server
            if ((bool)(string.Compare(classname.ToString(), "Internet Explorer_Server") == 0))
            {
                lParam = hWnd;
                retVal = 0;
            }
            return retVal;
        }
    }
}

请参阅此链接以获取更多信息:

http://www.xtremevbtalk.com/code-library/295336-internet-explorer-dom-using-objectfromlresult.html

于 2018-07-14T17:52:53.893 回答