0
votes

I have a Outlook Addin written in c#.

I have a form1, which is opened as a modal window on Outlook. At one point, I have to close the modal form1 with close & dispose; then I have to open another modal form - form2.

At this point, form2 stays at the very top of all windows, but, Outlook does not stay at immediate back.

It seems Windows brings the last application window on top after closing the first form, but does not bring Outlook behind form2 when form2 is opened.

Please suggest how to bring Outlook behind form2.

1

1 Answers

1
votes

You need to make sure your form is parented to an Outlook window correctly. You can cast Outlook Explorer or Inspector window (Application.ActiveWindow / ActiveExplorer / ActiveInspector) to the IOleWindow interface, call IOleWindow.GetWindow, then use the returned HWN to create an instance of the WindowInteropHelper object and set it as the owner of your form.

        [ComImport]
        [Guid("00000114-0000-0000-C000-000000000046")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IOleWindow
        {
            void GetWindow(out IntPtr phwnd);
            void ContextSensitiveHelp([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode);
        }