window doesn't gain focus after summon

Bug #364836 reported by Eyal Wiener
2
Affects Status Importance Assigned to Milestone
Mighty Box
Fix Committed
Critical
Unassigned

Bug Description

When summoning the command window, sometimes the window appears, top most, but doesn't gain focus.
This is critical, cause this happens many times, and when the window ain't got no focus, it doesn't capture keystrokes.

You can invoke this behavior by working on some app, calling MB to appear, and then, while the command window is open, click outside of it, back on the app. and from this moment forward, mighty box doesn't get *keyboard focus* when called while using this app. as if it had a higher precedence over it

Tags: gui

Related branches

Eyal Wiener (eyalw)
tags: added: gui
Changed in mb:
importance: Undecided → Critical
status: New → Confirmed
Eyal Wiener (eyalw)
description: updated
Revision history for this message
Eyal Wiener (eyalw) wrote :

I used Win32API to resolve this

[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(IntPtr hWnd);

[DllImport("user32")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

IntPtr hWnd = new WindowInteropHelper(MBMain.cmdWin).Handle;

uint TOPMOST_FLAGS = SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_ASYNCWINDOWPOS;
bool success = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, TOPMOST_FLAGS);

// Very very nasty hack:
while (SetForegroundWindow(hWnd) == 0) // on failure, try again
 Console.Write("#");
Console.WriteLine("@");

Changed in mb:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.