fix annoying toolstrip/menustrip non-clickthrough behaviour

This commit is contained in:
zeromus 2011-06-26 20:10:05 +00:00
parent 5fa8ae99fe
commit 33c5182296
4 changed files with 93 additions and 5 deletions

View File

@ -30,7 +30,7 @@
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.menuStrip1 = new MenuStripEx();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openROMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.recentROMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

View File

@ -30,7 +30,7 @@
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RamSearch));
this.SearchtoolStrip1 = new System.Windows.Forms.ToolStrip();
this.SearchtoolStrip1 = new ToolStripEx();
this.openToolStripButton = new System.Windows.Forms.ToolStripButton();
this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
@ -54,7 +54,7 @@
this.addToRamWatchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pokeAddressToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.freezeAddressToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.menuStrip1 = new MenuStripEx();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.newSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
@ -92,7 +92,7 @@
this.previewModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.alwaysExludeRamSearchListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStrip1 = new ToolStripEx();
this.NewSearchtoolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
@ -101,7 +101,7 @@
this.ClearChangeCountstoolStripButton = new System.Windows.Forms.ToolStripButton();
this.UndotoolStripButton = new System.Windows.Forms.ToolStripButton();
this.WatchtoolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.toolStrip2 = new System.Windows.Forms.ToolStrip();
this.toolStrip2 = new ToolStripEx();
this.DataSizetoolStripSplitButton1 = new System.Windows.Forms.ToolStripSplitButton();
this.byteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bytesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

View File

@ -101,6 +101,9 @@
<Compile Include="TextDebugView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ToolStripEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ViewportPanel.cs">
<SubType>Component</SubType>
</Compile>

View File

@ -0,0 +1,85 @@
//credit: http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
/// <summary>
/// This class adds on to the functionality provided in System.Windows.Forms.ToolStrip.
/// </summary>
public class ToolStripEx : ToolStrip
{
private bool clickThrough = true;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does
/// not have input focus.
/// </summary>
public bool ClickThrough
{
get
{
return this.clickThrough;
}
set
{
this.clickThrough = value;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (this.clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
/// <summary>
/// This class adds on to the functionality provided in System.Windows.Forms.MenuStrip.
/// </summary>
public class MenuStripEx : MenuStrip
{
private bool clickThrough = true;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does
/// not have input focus.
/// </summary>
public bool ClickThrough
{
get
{
return this.clickThrough;
}
set
{
this.clickThrough = value;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (this.clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
internal sealed class NativeConstants
{
private NativeConstants(){}
internal const uint WM_MOUSEACTIVATE = 0x21;
internal const uint MA_ACTIVATE = 1;
internal const uint MA_ACTIVATEANDEAT = 2;
internal const uint MA_NOACTIVATE = 3;
internal const uint MA_NOACTIVATEANDEAT = 4;
}