显示 Outlook 2013 main window 时识别事件(未加载屏幕)

Identify event when Outlook 2013 main window is shown (not loading screen)

我正在通过分析其子项 windows(类似于 here or here)自定义 Outlook UI,我必须在 Outlook 主 window 启动后立即执行此操作显示。

我通过在 OnStartupComplete 事件处理程序中调用 Process.GetCurrentProcess().MainWindowHandle 来接收 Outlook 主 window 处理程序。它在 Outlook 2007 和 Outlook 2010 中一定能正常工作,但 2013 年首先显示启动画面,然后才显示主 window 以及所有浏览器和检查器。问题是在显示此 "splash screen" 时发生 OnStartupComplete 事件,因此我没有收到正确的处理程序。 我尝试了一些肮脏的技巧,例如:

    1。签署资源管理器 `ViewSwitch` 事件。
    2。功能区 `OnLoad` 回调。
    3。选项卡“getVisible”回调。

不幸的是,没有任何帮助。它们都在 "splash screen" 显示时发生,因此 MainWindowHandle 指向它。

问题是当 MainWindowHandle 指向 Outlook 的主 window 时是否有任何方法可以定义触发器?

我进行了更多调查,发现主 Outlook window "rctrl_renwnd32" 是在显示初始屏幕时创建的,但它是不可见的。因此,为了获得 Outlook 主 window 句柄,我使用以下方法

    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, IntPtr windowTitle);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int processId);

    public static IntPtr GetOutlookMainHWnd ()
    {
        int curtProcId = Process.GetCurrentProcess().Id;
        int wndProcId = 0;
        IntPtr olMainHWnd = IntPtr.Zero;
        while (curtProcId != wndProcId) //this is to ensure that we get main window of our own process
        {
            olMainHWnd = NativeMethods.FindWindowEx(IntPtr.Zero, olMainHWnd, "rctrl_renwnd32", IntPtr.Zero);
            GetWindowThreadProcessId(olMainHWnd, out wndProcId);
        }

        return olMainHWnd;
    }

您可以简单地将 Explorer (Application.ActiveExplorer) 或 Inspector 对象转换为 IOleWindow 并调用 IOleWindow::GetWindow