Detecting whether Torque window has focus
by Ian Omroth Hardingham · in Torque Game Engine · 09/01/2009 (8:49 am) · 2 replies
Hey guys.
I have a very simple question. How do I find out if the Torque window has focus (ie, is the "selected" window).
Thanks,
Ian
I have a very simple question. How do I find out if the Torque window has focus (ie, is the "selected" window).
Thanks,
Ian
About the author
Designer and lead programmer on Frozen Synapse, Frozen Endzone, and Determinance. Co-owner of Mode 7 Games.
#2
In TorqueScript:
09/09/2009 (3:28 pm)
Somewhere around line 714 in winWindow.cccase WM_ACTIVATE:
windowActive = LOWORD(wParam) != WA_INACTIVE;
if( Game->isRunning() )
{
if (Con::isFunction("windowFocusChanged"))
Con::executef( 2, "windowFocusChanged", windowActive ? "1" : "0" );
}In TorqueScript:
function windowFocusChanged(%state)
{
if (%state == 1)
{
// Window got the focus
}
else
{
// Window lost the focus
}
}
Associate Ian Omroth Hardingham
Mode 7 Games
if (window && window != winState.appWindow && gWindowCreated)
{
// check to see if we are in the foreground or not
// if not Sleep for a bit or until a Win32 message/input is recieved
DWORD foregroundProcessId;
GetWindowThreadProcessId(window, &foregroundProcessId);
if (foregroundProcessId != winState.processId)
MsgWaitForMultipleObjects(0, NULL, false, getBackgroundSleepTime(), QS_ALLINPUT);
}
// if there's no window, we sleep 1, otherwise we sleep 0
else if(!Game->isJournalReading() && gWindowCreated )
Sleep( 1 ); // give others some process time if necessary...