How to detect whether or not user is running a full-screen program

Recently I was asked how to detect whether or not user is runing a full screen program,here is the code snippet: 

bool IsFullScreenMode()
{
  int w = GetSystemMetrics(SM_CXSCREEN);
  int h = GetSystemMetrics(SM_CYSCREEN); 

  HWND hWnd = 0;
  while (hWnd = FindWindowEx(NULL, hWnd, NULL, NULL))
  {
    if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
    {
      RECT rcWindow;
      GetWindowRect(hWnd, &rcWindow);
      if ((w == (rcWindow.right - rcWindow.left)) &&
         (h == (rcWindow.bottom - rcWindow.top)))
           return true;
     }
  }
  return false;
}
Related posts:

TAGS:


7 Comments »

free elegant wordpreass themes On June 10th, 2011 at 5:31 pm (#)

Good thanks alot :)

Pergo On October 12th, 2010 at 1:10 am (#)

GetForegroundWindow may actually work very well, if a check is also made for WS_EX_TOPMOST as in the above code.  The reason is that GetForegroundWindow seems to detect the desktop window as foreground in some cases, when no other windows are open on top of it.  And since the desktop is always full screen size, the detection returns true, even if nobody would ever consider the desktop to be in foreground.  It is not flagged as topmost however, so all should be ok.  Note that GetForegroundWindow may return NULL instead of a valid hWnd, and in this case the routine should simply end with returning false.

Lincoln Yeoh On January 23rd, 2010 at 4:24 am (#)

For a MultiMonitor environment it might be better to use: MonitorFromWindow() to figure out which monitor the window you are checking for "full screen" then GetMonitorInfo on the monitor to get its attributes. As for full-screen console windows there’s "GetConsoleDisplayMode" but I’m not sure how to specify a "current console".

erwin On December 10th, 2008 at 8:17 pm (#)

“isn’t it a bit faster to use GetForegroundWindow instead of this routine that has to check every window?” — Unfortunately it seems GetForegroundWindow is unreliable, sometimes it just doesn’t get the right window for some reason, so have to check them all instead.

case display flag On December 4th, 2008 at 7:01 am (#)

Just Look Here For a Sec, ImpressiveHello! case display flag cui

John Doe On August 29th, 2007 at 5:48 am (#)

Thanks for this nice piece of code, but isn’t it a bit faster to use GetForegroundWindow instead of this routine that has to check every window?

pillbug On June 30th, 2007 at 4:58 am (#)

Cool, thanks this is what I was looking for. Works for the couple of DirectX games I tried, but doesn’t work for full-screen console windows. Any ideas for that one?


Leave a comment


(will not be published)