More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 23-May-2019 09:47

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Code level: intermediate    Code area: Outlook and .NET Printer Friendly Version
Title: How to get the IWin32Window for Outlook
Description: This Class could be used to pass the Outlook as parent to .Net Forms and Messageboxes. Prevents Messageboxes hided by Outlook
Date: 11-Nov-2006  15:04
Code level: intermediate
Code area: Outlook and .NET
Posted by: Helmut Obertanner
This message is displayed as VB.NET
/// Outlook example code by H.Obertanner
/// Created 2006 with Office 2007 B2TR and VSTO 2005 SE
/// Free for non commercial use.
using System;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;

namespace OutlookAdminTools

  /// <summary>
  /// This class retrieves the IWin32Window from the current active Outlook window.
  /// This could be used to set the parent for Windows Forms and MessageBoxes.
  /// </summary>
  /// <example>
  ///  OutlookWin32Window parentWindow = new OutlookWin32Window (ThisAddIn.OutlookApplication.ActiveWindow ());    
  ///  MessageBox.Show (parentWindow, "This MessageBox doesn't go behind Outlook !!!", "Attention !", MessageBoxButtons.Ok , MessageBoxIcon.Question );
  /// </example>
  internal class OutlookWin32Window : IWin32Window

    /// <summary>
    /// The <b>FindWindow</b> method finds a window by it's classname and caption. 
    /// </summary>
    /// <param name="lpClassName">The classname of the window (use Spy++)</param>
    /// <param name="lpWindowName">The Caption of the window.</param>
    /// <returns>Returns a valid window handle or 0.</returns>
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    #region IWin32Window Members

    /// <summary>
    /// This holds the window handle for the found Window.
    /// </summary>
    IntPtr _windowHandle = IntPtr.Zero ;

    /// <summary>
    /// The <b>Handle</b> of the Outlook WindowObject.
    /// </summary>
    public IntPtr Handle
      get { return _windowHandle; }


    /// <summary>
    /// The <b>OutlookWin32Window</b> class could be used to get the parent IWin32Window for Windows.Forms and MessageBoxes.
    /// </summary>
    /// <param name="windowObject">The current WindowObject.</param>
    public OutlookWin32Window(object windowObject)
      string caption = windowObject.GetType().InvokeMember("Caption", System.Reflection.BindingFlags.GetProperty, null, windowObject, null).ToString();  

      // try to get the HWND ptr from the windowObject / could be an Inspector window or an explorer window
      _windowHandle = FindWindow("rctrl_renwnd32\0", caption);

All 5comments
Page [ 1  
  25-Apr-2008  03:40   
hi I have similar issue.

I have similar problem. I am developing a outlook 2003 shared addin. I want to add a button in reading pane. I knowI have to do this using Win32 however I do not know How to proceed. I have used the class which you have given above in code snipped however I am not knowing how to get handle for reading pane. After I get handle what do I have to do. Any inputs will be of great help
  25-Apr-2008  08:23   
Hello El Hannam,
can give us more details please ?
What are you trying to programm ?
Ann AddIn, IDExt2 or VSTO, or an Windows Forms Application ?
What Version of Office do you have installed ?
Greets, Helmut
  28-Apr-2008  02:33   
Hi Helmut
I have outlook 2003 installed
I am using shared addin with oulook 2003(extending IDTExtensibility2)
I have to add a button on the outlook 2003 reading pane. When I have my mouse on this button a windows form should open up with some information.

Can you guide me to some win32 api's where I can get some information how to achieve this.
  10-Sep-2008  06:46   
Hi vidisha,
Any news on that? I have the same problem.....
  10-Sep-2008  12:11   
Hi all,
here I found this wonderful article.
Maybe you can add an additional Panel on top of the Reading Pane and put in a Button here.

Hope this helps,
greets - Helmut
Page [ 1