SFML community forums

Help => Window => Topic started by: m00npirate on November 15, 2011, 07:20:40 am

Title: Getting back window focus
Post by: m00npirate on November 15, 2011, 07:20:40 am
I fear I may know the answer to this question but:

I have a "console application" in VS2010 set up using SFML2.net, and whenever I boot up the game in the debugger, first VS's debug console pops up, and then the SFML window (expected). However, even though the SFML window is physically on top of the debug console, it is the debug console which retains focus. Is there any workaround for this? It means one extra click every time I debug my game.

My fear then is that this is an issue specific to VS or how windows 7 handles focus. It there any way to force the SFML window to the front? Even a system call would be fine since the console will only be there when I'm debugging it. When I remove the console the window is properly in front.
Title: Getting back window focus
Post by: Laurent on November 15, 2011, 07:35:04 am
You can try SetForegroundWindow(window.GetSystemHandle()) (include <windows.h>).

But it's strange, I never got this problem with VS + Windows 7.
Title: Getting back window focus
Post by: m00npirate on November 15, 2011, 08:19:37 am
Perfect!


Thanks.

Code: [Select]


[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

protected RenderWindow window;

public void ForceToFront()
{
    SetForegroundWindow(window.SystemHandle);
}