locked
Outlook close after closing a dialog RRS feed

  • Question

  • Hello,

    I have created an AddIn for Outlook. In this I have to open a dialog (Windows form). If I open my dialog as modal window I have no problems. If I open the dialog as non modal window then Outlook closes after I close my dialog.

    Has anyone any idea what could be my problem?

    Thursday, March 24, 2016 2:11 PM

Answers

  • Hello Benjamin,

    You need to specify the parent window handle for your dialog. You can cast the Explorer or Inspector instance to the IOleWindow interface. The IOleWindow interface provides methods that allow an application to obtain the handle to the various windows that participate in in-place activation, and also to enter and exit context-sensitive help mode. The GetWindow method of the IOleWindow interface retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window).

    Then you can specify the window handle to the Show or ShowDialog method of the Form class. You just need to pass an instance of the IWin32Window interface to methods. You can use the following class to specify the window handle:

    public class WindowWrapper : System.Windows.Forms.IWin32Window
    {
        public WindowWrapper(IntPtr handle)
        {
            _hwnd = handle;
        }
    
        public IntPtr Handle
        {
            get { return _hwnd; }
        }
    
        private IntPtr _hwnd;
    }

    Thursday, March 24, 2016 2:54 PM

All replies

  • Hello Benjamin,

    You need to specify the parent window handle for your dialog. You can cast the Explorer or Inspector instance to the IOleWindow interface. The IOleWindow interface provides methods that allow an application to obtain the handle to the various windows that participate in in-place activation, and also to enter and exit context-sensitive help mode. The GetWindow method of the IOleWindow interface retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window).

    Then you can specify the window handle to the Show or ShowDialog method of the Form class. You just need to pass an instance of the IWin32Window interface to methods. You can use the following class to specify the window handle:

    public class WindowWrapper : System.Windows.Forms.IWin32Window
    {
        public WindowWrapper(IntPtr handle)
        {
            _hwnd = handle;
        }
    
        public IntPtr Handle
        {
            get { return _hwnd; }
        }
    
        private IntPtr _hwnd;
    }

    Thursday, March 24, 2016 2:54 PM
  • Hello Eugene,

    thank you for your quickly answer.

    The Problem is that I must show my dialog in a non modal window. Because in this window I store other emails as .msg file and I want open this. But I can open a msg file only if Outlook has no modal dialog open.

    Thursday, March 24, 2016 3:04 PM
  • Benjamin,

    You need to use the Show method of the Form class then. It also allow to specify the parent window handle using the IWin32Window interface. 

    Thursday, March 24, 2016 5:58 PM
  • Hello,

    I resolve my problem otherwise, thank you anyway.

    Wednesday, March 30, 2016 6:40 AM