none
Hiding Outlook inspector window when opening mailItem in Outlook 2003 RRS feed

  • Question

  • Hi all,

    I am creating an add-in for Outlook 2003 with C#.

    I have a requirement where for some mailItems in outlook I want to stop them from opening in an inspector window and open a URL. I have successfully identified the mailItems and opened the URL, but the Inspector is briefly shown on some (slow) machines.

    I am setting "cancel=true" in the OpenEventHandler method, but the Inspector is made visible even before that. That is why I accessed the NewInspectorEventHandler and ActivateEventHandler.


    But the inspector window is made visible after the last line in the Open_NewInspector() method and before the first line in the InspectorActivate() method. Attempting to set the WindowState property in Open_NewInspector() will throw an error stating that the window is not made visible yet. Setting the WindowState property in the InspectorActivate() method (as in the code below) will still briefly flash the inspector window to the user before hiding it.

    I need to ensure that the user does not see the inspector window at all while the URL is being opened.

    My test machine (where the issue is seen) is a P4 3GHz 248MB RAM machine running WinXP SP3. My dev machine is a Pentium G620 2.6GHz 4GB RAM running Win7. I am unable to simulate the issue at all on my dev machine. That is, the inspector window is not shown even if I put a break point in the mail_Edit() method to stop it from returning "cancel=false" for a while.

    Can someone give me a solution on how to ensure the inspector is hidden?

    Following is an extraction of my code relevant for the process:

    private Microsoft.Office.Interop.Outlook.Inspectors _inspectors;
    private Microsoft.Office.Interop.Outlook.Explorer _currentExplorer;
    
    
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
    {
            _inspectors = application.Inspectors;
            _currentExplorer = application.ActiveExplorer();
            _inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(this.Open_NewInspector);
            //add handler to explorer selectionChange event, fires when item is selected
            _currentExplorer.SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(this.OnSelectChange);
    
    }
    
    public void OnSelectChange()
    {
            if(<selectedMailItem is the type I require>)
            {
                    mailItem.Open += new Microsoft.Office.Interop.Outlook.ItemEvents_10_OpenEventHandler(mail_Edit);
            }
    }
    
    public void mail_Edit(ref bool cancel)
    {
            //Open URL
            cancel= true;
    }
    
    private void Open_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
            if(<check mail type to open inspector is my mail type>)
            {
                    ((Microsoft.Office.Interop.Outlook.InspectorEvents_10_Event)newMailInspector).Activate += new Microsoft.Office.Interop.Outlook.InspectorEvents_10_ActivateEventHandler(InspectorActivate);
            }
    }
    
    private void InspectorActivate()
    {
            try
            {
                    if (newMailInspector.WindowState == Microsoft.Office.Interop.Outlook.OlWindowState.olMaximized || newMailInspector.WindowState == Microsoft.Office.Interop.Outlook.OlWindowState.olNormalWindow)
                            newMailInspector.WindowState = Microsoft.Office.Interop.Outlook.OlWindowState.olMinimized;
            }
            catch (System.Exception ex)
            {
                    MessageBox.Show(ex.Message, "Activate");
            }
    }

    Thanks!!

    - Thimila H. Fernando


    Tuesday, January 29, 2013 5:34 AM

Answers

  • normally just setting Cancel = true on mail's Open event is sufficient - please check if on the other machine where brief flash of inspector is shown if mail editor is set to Word - if so, uncheck this option and try again.
    Tuesday, January 29, 2013 7:43 AM
  • no, i do not think there is such option. And in any way you should honor client settings. Problem occurs because on outlook 2003 when word editor is used, whole inspector is shown in different thread and this happens due to marshalling issues and i;m not sure if i have any solution for this. Maybe other, more experienced users here will be able to help you.
    Wednesday, January 30, 2013 5:22 AM
  • one more thing - you will have to do investigation yourself though:

    Please check (using System.Threading.Thread.Current.Thread.ManagedId) if one of those events that you attached to runs in new thread along with word based inspector - if it does and this event is raised before inspector window is shown, there is hope - you could install there message pump hooks that would swallow paint requests and window would never draw before your cancellation request would be processed from other thread.

    Wednesday, January 30, 2013 7:39 AM

All replies

  • normally just setting Cancel = true on mail's Open event is sufficient - please check if on the other machine where brief flash of inspector is shown if mail editor is set to Word - if so, uncheck this option and try again.
    Tuesday, January 29, 2013 7:43 AM
  • Thanks Damian, that was the issue on the test machine.

    However, now my question is if the users of my application want to have word as their editor for any other accounts that they have on Outlook, I do not want the inspector to flash when they try to open my mail items.

    Is there a way I can disable/enable that feature in my code before the inspector is created? Say, uncheck set editor to word in the OnSelectChange() or Open_NewInspector() methods, and reset to word at the end of the mail's Open event?

    --EDIT--

    I have tried setting

                 mailItem.FormDescription.UseWordMail = false;

    but it does not seem to work.

    -------

    Thanks!



    Tuesday, January 29, 2013 10:23 PM
  • no, i do not think there is such option. And in any way you should honor client settings. Problem occurs because on outlook 2003 when word editor is used, whole inspector is shown in different thread and this happens due to marshalling issues and i;m not sure if i have any solution for this. Maybe other, more experienced users here will be able to help you.
    Wednesday, January 30, 2013 5:22 AM
  • Thanks Damian. Hopefully someone will be able to help me.

    Wednesday, January 30, 2013 6:15 AM
  • one more thing - you will have to do investigation yourself though:

    Please check (using System.Threading.Thread.Current.Thread.ManagedId) if one of those events that you attached to runs in new thread along with word based inspector - if it does and this event is raised before inspector window is shown, there is hope - you could install there message pump hooks that would swallow paint requests and window would never draw before your cancellation request would be processed from other thread.

    Wednesday, January 30, 2013 7:39 AM