1

数時間の実験とグーグル検索の後、私はついに自分で理解できるものの終わりに達したので、ここに私が今持っているものがあります:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Application.Startup += new
        Outlook.ApplicationEvents_11_StartupEventHandler(
        ApplicationObject_Startup);
    ((Outlook.ApplicationEvents_11_Event)Application).Quit += new
        Outlook.ApplicationEvents_11_QuitEventHandler(
        ApplicationObject_Quit);
}
void ApplicationObject_Startup()
{
    MessageBox.Show("Startup Event");
    ((Outlook.ExplorerEvents_10_Event)Application.ActiveExplorer()).Close += new
        Outlook.ExplorerEvents_10_CloseEventHandler(
        ExplorerObject_Close);
}

void ApplicationObject_Quit()
{
    MessageBox.Show("Quit Event");
}

void ExplorerObject_Close()
{
    MessageBox.Show("Explorer Close Event");
}

これはすべて機能し、Outlook を閉じると、エクスプローラーの終了イベントと終了イベントのメッセージ ボックスが順番に表示されます。ただし、この時点で見通しはすでに閉じているようで、これらのイベントをキャンセルする方法がわかりません (他のいくつかのイベントでは、false に設定できる bool Cancel が渡されますが、これらのイベントではできませんか?)、または送信します。最小化イベント(これを理解する方法がまったくありませんでした)。

誰か提案があれば、本当に感謝しています。私は仕事にいくらかの空き時間を持っていたので、いくつかのアドイン開発のことを学び、同時に Outlook の本当に厄介な部分を解決しようと考えました!

編集:私も試しました:

Application.ActiveExplorer().WindowState = Outlook.OlWindowState.olMinimized;

起動時にウィンドウをすぐに最小化します。それは見通しを最小化しますが、システムトレイではなく、バーにのみ適用します(最小化はトレイに最小化するように設定されているため、これは面白いことであり、おそらく実際にはバグです...)それでも、クローズを取り除くことができれば/quit event(s) 少なくともウィンドウをタスクバーに最小化できました。

4

1 に答える 1

2
private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        try
        {
            // Assign startup and quit events
            Application.Startup += new Outlook.ApplicationEvents_11_StartupEventHandler(ApplicationObject_Startup);
            ((Outlook.ApplicationEvents_11_Event)Application).Quit += new Outlook.ApplicationEvents_11_QuitEventHandler(ApplicationObject_Quit);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
        try
        {
            // Remove the startup and quit events
            Application.Startup -= new Outlook.ApplicationEvents_11_StartupEventHandler(ApplicationObject_Startup);
            ((Outlook.ApplicationEvents_11_Event)Application).Quit -= new Outlook.ApplicationEvents_11_QuitEventHandler(ApplicationObject_Quit);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    void ApplicationObject_Startup()
    {
        try
        {
            // Minimize to taskbar
            Application.ActiveExplorer().WindowState = Outlook.OlWindowState.olMinimized;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    void ApplicationObject_Quit()
    {
        try
        {
            // Restart outlook minimized
            ProcessStartInfo psiOutlook = new ProcessStartInfo("OUTLOOK.EXE", "/recycle");
            psiOutlook.WindowStyle = ProcessWindowStyle.Minimized;
            Process.Start(psiOutlook);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

あまりきれいではありませんが、これでうまくいきました。Outlook を閉じると、Outlook の新しいインスタンスが起動され、起動時に Outlook が常に最小化されます。もちろん、主な欠点は、最初にアドインを無効にするか、タスク マネージャーで "outlook.exe" を強制終了しないと、Outlook を実際に閉じることができないことです。最善の解決策ではありませんが、誤って Outlook を閉じてしまったためにメールやカレンダーのリマインダーを見逃すことはありません。

編集(10/02/12): コードの再起動の見通し部分を更新しました。/recycle スイッチを使用して outlook.exe を開始するようになりました。これは、既存のウィンドウで Outlook を再読み込みしようとします。また、最小化されたウィンドウ スタイルを使用して Outlook を再起動します。これにより、Outlook の読み込みウィンドウが表示されなくなります。

于 2012-08-31T21:13:10.067 に答える