I don't know if this will help anyone else, but it seems to be the best option for my game.
foreground = GetForegroundWindow();
if(foreground!=hWnd)
{
beep();
proc_mode = PROC_NOFREEZE;
freeze_mode = 2;
while(1)
{
foreground = GetForegroundWindow();
if(foreground==hWnd)
{
freeze_mode = 0;
proc_mode = PROC_GLOBAL;
break;
}
wait(1);
}
wait(1);
beep();
}
Since my game does not need to run in the background, I just froze it whenever it was not the foreground window. It's based on Emri's code, but adjusted slightly. This is all in another while loop that I use for other things, like calculating fps and some other general purpose scripts.