diff --git a/OutlookCloseToMinimize.csproj b/OutlookCloseToMinimize.csproj
new file mode 100644
index 0000000..aefa91e
--- /dev/null
+++ b/OutlookCloseToMinimize.csproj
@@ -0,0 +1,222 @@
+
+
+
+
+ {BAA0C2D2-18E2-41B9-852F-F413020CAA33};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ Debug
+ AnyCPU
+ {A37168BF-4330-4D80-8099-A7ADF94B21C2}
+ Library
+ false
+ OutlookCloseToMinimize
+ OutlookCloseToMinimize
+ 3
+ v4.7.2
+ VSTO40
+ true
+ HomeSite
+
+
+
+ False
+ Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29
+ true
+
+
+
+
+ Outlook
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ false
+ $(DefineConstants);DEBUG;TRACE
+ 4
+
+
+
+ pdbonly
+ true
+ bin\Release\
+ false
+ $(DefineConstants);TRACE
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+
+ True
+
+
+ True
+
+
+
+
+ False
+ true
+
+
+ False
+ true
+
+
+ False
+
+
+
+
+
+ Code
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+
+
+ Code
+
+
+ ThisAddIn.cs
+
+
+ ThisAddIn.Designer.xml
+
+
+
+
+ 10.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+ true
+
+
+ OutlookCloseToMinimize_TemporaryKey.pfx
+
+
+ 57790B38ED1DCC54FE9462FCB72ACD2552AE477A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OutlookCloseToMinimize.sln b/OutlookCloseToMinimize.sln
new file mode 100644
index 0000000..941e070
--- /dev/null
+++ b/OutlookCloseToMinimize.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31702.278
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OutlookCloseToMinimize", "OutlookCloseToMinimize.csproj", "{A37168BF-4330-4D80-8099-A7ADF94B21C2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A37168BF-4330-4D80-8099-A7ADF94B21C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A37168BF-4330-4D80-8099-A7ADF94B21C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A37168BF-4330-4D80-8099-A7ADF94B21C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A37168BF-4330-4D80-8099-A7ADF94B21C2}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {08E17BA9-A253-4B5E-8B87-12210555F0EB}
+ EndGlobalSection
+EndGlobal
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9c1a095
--- /dev/null
+++ b/Properties/AssemblyInfo.cs
@@ -0,0 +1,38 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("OutlookCloseToMinimize")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("OutlookCloseToMinimize")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("b2a9b09b-3e6f-48af-b2f7-2092fd275b39")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..8e60ebe
--- /dev/null
+++ b/Properties/Resources.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace OutlookCloseToMinimize.Properties {
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OutlookCloseToMinimize.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..ebcca5d
--- /dev/null
+++ b/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace OutlookCloseToMinimize.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/Properties/Settings.settings b/Properties/Settings.settings
new file mode 100644
index 0000000..3964565
--- /dev/null
+++ b/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/ThisAddIn.Designer.cs b/ThisAddIn.Designer.cs
new file mode 100644
index 0000000..92beb72
--- /dev/null
+++ b/ThisAddIn.Designer.cs
@@ -0,0 +1,286 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 414
+namespace OutlookCloseToMinimize {
+
+
+ ///
+ [Microsoft.VisualStudio.Tools.Applications.Runtime.StartupObjectAttribute(0)]
+ [global::System.Security.Permissions.PermissionSetAttribute(global::System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
+ public sealed partial class ThisAddIn : Microsoft.Office.Tools.Outlook.OutlookAddInBase {
+
+ internal Microsoft.Office.Tools.CustomTaskPaneCollection CustomTaskPanes;
+
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ private global::System.Object missing = global::System.Type.Missing;
+
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ internal Microsoft.Office.Interop.Outlook.Application Application;
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ public ThisAddIn(global::Microsoft.Office.Tools.Outlook.Factory factory, global::System.IServiceProvider serviceProvider) :
+ base(factory, serviceProvider, "AddIn", "ThisAddIn") {
+ Globals.Factory = factory;
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ protected override void Initialize() {
+ base.Initialize();
+ this.Application = this.GetHostItem(typeof(Microsoft.Office.Interop.Outlook.Application), "Application");
+ Globals.ThisAddIn = this;
+ global::System.Windows.Forms.Application.EnableVisualStyles();
+ this.InitializeCachedData();
+ this.InitializeControls();
+ this.InitializeComponents();
+ this.InitializeData();
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ protected override void FinishInitialization() {
+ this.InternalStartup();
+ this.OnStartup();
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ protected override void InitializeDataBindings() {
+ this.BeginInitialization();
+ this.BindToData();
+ this.EndInitialization();
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void InitializeCachedData() {
+ if ((this.DataHost == null)) {
+ return;
+ }
+ if (this.DataHost.IsCacheInitialized) {
+ this.DataHost.FillCachedData(this);
+ }
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void InitializeData() {
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void BindToData() {
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ private void StartCaching(string MemberName) {
+ this.DataHost.StartCaching(this, MemberName);
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ private void StopCaching(string MemberName) {
+ this.DataHost.StopCaching(this, MemberName);
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ private bool IsCached(string MemberName) {
+ return this.DataHost.IsCached(this, MemberName);
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void BeginInitialization() {
+ this.BeginInit();
+ this.CustomTaskPanes.BeginInit();
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void EndInitialization() {
+ this.CustomTaskPanes.EndInit();
+ this.EndInit();
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void InitializeControls() {
+ this.CustomTaskPanes = Globals.Factory.CreateCustomTaskPaneCollection(null, null, "CustomTaskPanes", "CustomTaskPanes", this);
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ private void InitializeComponents() {
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ private bool NeedsFill(string MemberName) {
+ return this.DataHost.NeedsFill(this, MemberName);
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
+ protected override void OnShutdown() {
+ this.CustomTaskPanes.Dispose();
+ base.OnShutdown();
+ }
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ internal sealed partial class Globals {
+
+ ///
+ private Globals() {
+ }
+
+ private static ThisAddIn _ThisAddIn;
+
+ private static global::Microsoft.Office.Tools.Outlook.Factory _factory;
+
+ private static ThisRibbonCollection _ThisRibbonCollection;
+
+ private static ThisFormRegionCollection _ThisFormRegionCollection;
+
+ internal static ThisAddIn ThisAddIn {
+ get {
+ return _ThisAddIn;
+ }
+ set {
+ if ((_ThisAddIn == null)) {
+ _ThisAddIn = value;
+ }
+ else {
+ throw new System.NotSupportedException();
+ }
+ }
+ }
+
+ internal static global::Microsoft.Office.Tools.Outlook.Factory Factory {
+ get {
+ return _factory;
+ }
+ set {
+ if ((_factory == null)) {
+ _factory = value;
+ }
+ else {
+ throw new System.NotSupportedException();
+ }
+ }
+ }
+
+ internal static ThisRibbonCollection Ribbons {
+ get {
+ if ((_ThisRibbonCollection == null)) {
+ _ThisRibbonCollection = new ThisRibbonCollection(_factory.GetRibbonFactory());
+ }
+ return _ThisRibbonCollection;
+ }
+ }
+
+ internal static ThisFormRegionCollection FormRegions {
+ get {
+ if ((_ThisFormRegionCollection == null)) {
+ _ThisFormRegionCollection = new ThisFormRegionCollection(Globals.ThisAddIn.GetFormRegions());
+ }
+ return _ThisFormRegionCollection;
+ }
+ }
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Tools.Office.ProgrammingModel.dll", "16.0.0.0")]
+ internal sealed partial class ThisRibbonCollection : Microsoft.Office.Tools.Ribbon.RibbonCollectionBase {
+
+ ///
+ internal ThisRibbonCollection(global::Microsoft.Office.Tools.Ribbon.RibbonFactory factory) :
+ base(factory) {
+ }
+
+ internal ThisRibbonCollection this[Microsoft.Office.Interop.Outlook.Inspector inspector] {
+ get {
+ return this.GetRibbonContextCollection(inspector);
+ }
+ }
+
+ internal ThisRibbonCollection this[Microsoft.Office.Interop.Outlook.Explorer explorer] {
+ get {
+ return this.GetRibbonContextCollection(explorer);
+ }
+ }
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ internal sealed partial class ThisFormRegionCollection : Microsoft.Office.Tools.Outlook.FormRegionCollectionBase {
+
+ ///
+ public ThisFormRegionCollection(System.Collections.Generic.IList list) :
+ base(list) {
+ }
+
+ internal WindowFormRegionCollection this[Microsoft.Office.Interop.Outlook.Explorer explorer] {
+ get {
+ return ((WindowFormRegionCollection)(Globals.ThisAddIn.GetFormRegions(explorer, typeof(WindowFormRegionCollection))));
+ }
+ }
+
+ internal WindowFormRegionCollection this[Microsoft.Office.Interop.Outlook.Inspector inspector] {
+ get {
+ return ((WindowFormRegionCollection)(Globals.ThisAddIn.GetFormRegions(inspector, typeof(WindowFormRegionCollection))));
+ }
+ }
+ }
+
+ ///
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ internal sealed partial class WindowFormRegionCollection : Microsoft.Office.Tools.Outlook.FormRegionCollectionBase {
+
+ ///
+ public WindowFormRegionCollection(System.Collections.Generic.IList list) :
+ base(list) {
+ }
+ }
+}
diff --git a/ThisAddIn.Designer.xml b/ThisAddIn.Designer.xml
new file mode 100644
index 0000000..d70f58c
--- /dev/null
+++ b/ThisAddIn.Designer.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/ThisAddIn.cs b/ThisAddIn.cs
new file mode 100644
index 0000000..b49ab42
--- /dev/null
+++ b/ThisAddIn.cs
@@ -0,0 +1,85 @@
+using System;
+using Outlook = Microsoft.Office.Interop.Outlook;
+using System.Runtime.InteropServices;
+
+namespace OutlookCloseToMinimize {
+ [ComImport]
+ [Guid("00000114-0000-0000-C000-000000000046")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IOleWindow {
+ int GetWindow(out IntPtr phwnd);
+ int ContextSensitiveHelp([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode);
+ }
+
+ public partial class ThisAddIn {
+ [DllImport("comctl32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool SetWindowSubclass(IntPtr hWnd, IntPtr pfnSubclass, UIntPtr uIdSubclass, UIntPtr dwRefData);
+ [DllImport("comctl32.dll")]
+ static extern IntPtr DefSubclassProc(IntPtr hWnd, uint uMsg, UIntPtr wParam, IntPtr lParam);
+ [DllImport("comctl32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool RemoveWindowSubclass(IntPtr hWnd, IntPtr pfnSubclass, UIntPtr uIdSubclass);
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
+
+ delegate IntPtr SubclassProc(IntPtr hWnd, uint uMsg, UIntPtr wParam, IntPtr lParam, UIntPtr uIdSubclass, UIntPtr dwRefData);
+
+ const int S_OK = 0;
+ const uint WM_CLOSE = 0x0010;
+ const int SW_MINIMIZE = 6;
+
+ IntPtr _hWnd = IntPtr.Zero, _scProc = IntPtr.Zero;
+ GCHandle _gch;
+
+ IntPtr MySubclassProc(IntPtr hWnd, uint uMsg, UIntPtr wParam, IntPtr lParam, UIntPtr uIdSubclass, UIntPtr dwRefData) {
+ if (uMsg == WM_CLOSE) {
+ ShowWindow(hWnd, SW_MINIMIZE);
+ return IntPtr.Zero;
+ }
+ return DefSubclassProc(hWnd, uMsg, wParam, lParam);
+ }
+
+ private void ThisAddIn_Startup(object sender, System.EventArgs e) {
+ // Outlook doesn't send Shutdown events on close any more,
+ // so we need to hook the Quit event to remove our subclass callback
+ // before our module is unloaded to avoid crashes
+ ((Outlook.ApplicationEvents_11_Event)Application).Quit += ThisAddIn_Quit;
+ if (((IOleWindow)Application.ActiveExplorer()).GetWindow(out _hWnd) == S_OK && _hWnd != IntPtr.Zero) {
+ _gch = GCHandle.Alloc(this);
+ _scProc = Marshal.GetFunctionPointerForDelegate((SubclassProc)MySubclassProc);
+ if (SetWindowSubclass(_hWnd, _scProc, UIntPtr.Zero, UIntPtr.Zero)) {
+ return;
+ }
+ _gch.Free();
+ }
+ _hWnd = IntPtr.Zero;
+ }
+
+ private void ThisAddIn_Quit() {
+ if (_hWnd != IntPtr.Zero) {
+ RemoveWindowSubclass(_hWnd, _scProc, UIntPtr.Zero);
+ _hWnd = IntPtr.Zero;
+ _gch.Free();
+ }
+ }
+
+ private void ThisAddIn_Shutdown(object sender, System.EventArgs e) {
+ ThisAddIn_Quit();
+ }
+
+ #region VSTO generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InternalStartup() {
+ this.Startup += new System.EventHandler(ThisAddIn_Startup);
+ this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
+ }
+
+ #endregion
+ }
+}