Created
March 28, 2019 18:59
-
-
Save davecra/3b349673ca41746ff805c848a6c1fef6 to your computer and use it in GitHub Desktop.
IMessageFilter implementation in Excel VSTO Add-in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
using System.Runtime.InteropServices; | |
namespace ExcelOleFilterAddIn | |
{ | |
public partial class ThisAddIn : ExcelOleFilterAddIn.IMessageFilter | |
{ | |
[DllImport("ole32.dll")] | |
static extern int CoRegisterMessageFilter(IMessageFilter lpMessageFilter, out IMessageFilter lplpMessageFilter); | |
private IMessageFilter oldMessageFilter; | |
private void RegisterFilter() | |
{ | |
CoRegisterMessageFilter(this, out oldMessageFilter); | |
} | |
int IMessageFilter.HandleInComingCall(uint dwCallType, IntPtr htaskCaller, uint dwTickCount, INTERFACEINFO[] lpInterfaceInfo) | |
{ | |
MessageBox.Show("The caller is: " + htaskCaller.ToString()); | |
return 1; | |
} | |
int IMessageFilter.RetryRejectedCall(IntPtr htaskCallee, uint dwTickCount, uint dwRejectType) | |
{ | |
return 1; | |
} | |
int IMessageFilter.MessagePending(IntPtr htaskCallee, uint dwTickCount, uint dwPendingType) | |
{ | |
return 1; | |
} | |
private void ThisAddIn_Startup(object sender, System.EventArgs e) | |
{ | |
RegisterFilter(); | |
} | |
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) | |
{ | |
} | |
#region VSTO generated code | |
/// <summary> | |
/// Required method for Designer support - do not modify | |
/// the contents of this method with the code editor. | |
/// </summary> | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(ThisAddIn_Startup); | |
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment