To prevent switching to window on left click I am handling WM_MOUSEACTIVATE and it works unless I am testing for mouse button state. The button state here will show as Released even though left button down is used to call this event and held.
private const int WM_MOUSEACTIVATE = 0x0021;
private const uint MA_NOACTIVATE = 3;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_MOUSEACTIVATE)
{
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
handled = true;
return (IntPtr)MA_NOACTIVATE ;
The WM_LBUTTONDOWN is received only after the WM_MOUSEACTIVATE, and I expected that static Mouse.LeftButton would return the current value regardless. Is there a better way to get a current state of the mouse left button?
You don't really have to use WndProc at all. You can use a UIElement.PreviewMouseDown Event and refer to the MouseButtonEventArgs to get the state information.