I’m currently building a multi-process desktop application suite that has a “launch bar” tool to start up instances of all the available widgets. A simple Winforms ToolStrip control seemed the obvious choice for creating a nice consistent strip of buttons, but I came across the issue that if the launch bar did not have focus, then it took 2 clicks to launch a widget when clicking on a button – one to activate the application and one to click the button.
Having Googled extensively I found that this interaction is not in fact a bug, but actually designed behaviour. I would normally accept this and move on, but I found it particularly inconsistent that the ToolStrip buttons actually illuminate/highlight on mouseover even when the app doesn’t have focus – thus fooling the user into thinking that they need only click once.
Finally,I found a few helpful articles – especially this one by Rick Brewster. The solution lies in overriding the WndProc method for the ToolStrip (or MenuStrip):
protected override void WndProc(ref Message m)
if (this.clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;