Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting back window focus  (Read 2810 times)

0 Members and 1 Guest are viewing this topic.

m00npirate

  • Newbie
  • *
  • Posts: 18
    • View Profile
Getting back window focus
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting back window focus
« Reply #1 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.
Laurent Gomila - SFML developer

m00npirate

  • Newbie
  • *
  • Posts: 18
    • View Profile
Getting back window focus
« Reply #2 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);
}


 

anything