0
votes

I have an Outlook 2013 VSTO addin. I'm trying to center my saveFileDialog on the parent. I read that you can overload the ShowDialog() method with a IWin32Window handle. I can't find any examples to show how to get this IWin32Window handle. How can I get the IWin32Window handle for Outlook so I can pass it to ShowDialog() and center the saveFileDialog() on the parent window.

From what I read just passing in the handle isn't enough. Seems there is an extra step but I can't for the life of me find it.

If anyone can provide an example of how to capture the handle and then center the window on the parent for a saveFileDialog() it would be a huge help.

Thanks

1

1 Answers

1
votes

You need to create an instance of the IWin32Window interface to pass it to the Show or ShowDialog method of the Form class. For example, you can use the following code:

 public class WindowHandle : System.Windows.Forms.IWin32Window
 {
      public WindowHandle(IntPtr handle)
      {
          _hwnd = handle;
      }

      public IntPtr Handle
      {
          get { return _hwnd; }
      }

      private IntPtr _hwnd;
   }

To get the window handle you can convert an instance of the Explorer or Inspector class to the IOleWindow interface. The GetWindow method allows to retrieve a handle to the window.