skip to Main Content

We have a VSTO plugin, and we are required to black out the email window of open mails. If it has to be done via SetWindowDisplayAffinity, how do we get the right handle to SetWindowDisplayAffinity via a VSTO plugin?

We did attempt to SetWindowDisplayAffinity via the handle we got via the process but it had no effect

2

Answers


  1. Cast the Inspector Outlook object to the IOleWindow interface (also works with the Explorer objects too) and call IOleWindow::GetWindow to get its HWND.

    Login or Signup to reply.
  2. You can retrieve the window handle that can be used for the function by casting the Outlook window instance like Explorer or Inspector to the IOLEWindow interface and using the IOleWindow::GetWindow method which retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window).

    Here is the sample code which shows how to use the IOLEWindow interface with Outlook windows:

    /// <summary>
     /// Implemented and used by containers and objects to obtain window handles 
     /// and manage context-sensitive help.
     /// </summary>
     /// <remarks>
     /// 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.
     /// </remarks>
     [ComImport]
     [Guid("00000114-0000-0000-C000-000000000046")]
     [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
     public interface IOleWindow
     {
         /// <summary>
         /// Returns the window handle to one of the windows participating in in-place activation 
         /// (frame, document, parent, or in-place object window).
         /// </summary>
         /// <param name="phwnd">Pointer to where to return the window handle.</param>
         void GetWindow (out IntPtr phwnd) ;
    
         /// <summary>
         /// Determines whether context-sensitive help mode should be entered during an 
         /// in-place activation session.
         /// </summary>
         /// <param name="fEnterMode"><c>true</c> if help mode should be entered; 
         /// <c>false</c> if it should be exited.</param>
         void ContextSensitiveHelp ([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode) ;
     }
    
     public void getWindowHandle()
     {
            dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
            IOleWindow win = activeWindow as IOleWindow;
            IntPtr window = IntPtr.Zero; 
            win.GetWindow(window);
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search