Shoutbox

How to detect fullscreen application? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: How to detect fullscreen application? (/showthread.php?tid=95929)

How to detect fullscreen application? by V@no on 11-28-2010 at 05:25 PM

Hello!

WLM by itself has compatibility to detect fullscreen application. Can we use that feature in our scripts?
Or is there another way detect it?

So far I could only find Detect Full Screen application topic, I've tried proposed code but it fails: when WMP is in fullscreen, it fails at GetWindowRect check, on PotPlayer it fails at IsIconic.

The code:

Javascript code:
// Check if full screen app is running
function IsFullScreenAppRunning ()
{
  var hWnd = Interop.Call('user32', 'GetForegroundWindow');
 
  if(!hWnd)
  {
    Debug.Trace(1);
    return false;
  }
 
  if(!Interop.Call('user32', 'IsWindowVisible', hWnd) || Interop.Call('user32', 'IsIconic', hWnd) || !Interop.Call('user32', 'IsZoomed', hWnd))
  {
    Debug.Trace(2 + " | " + Interop.Call('user32', 'IsWindowVisible', hWnd) + " | " +Interop.Call('user32', 'IsIconic', hWnd) + " | " +Interop.Call('user32', 'IsZoomed', hWnd));
    return false;
  }
 
  var rc;
 
  if(!Interop.Call('user32', 'GetWindowRect', hWnd, rc))
  {
    Debug.Trace(3);
    return false;
  }
  Debug.Trace(4 + " | " + rc.right + " | " + rc.left + " | " + Interop.Call('user32', 'GetSystemMetrics', SM_CXSCREEN));
  return (rc.right - rc.left  >= Interop.Call('user32', 'GetSystemMetrics', SM_CXSCREEN) &&  rc.bottom - rc.top >= Interop.Call('user32', 'GetSystemMetrics', SM_CYSCREEN));
}


Any help would be appreciated.

Thank you.
RE: How to detect fullscreen application? by Matti on 11-28-2010 at 06:13 PM

Your conversion from C++ is faulty. There are no structure types (RECT) or pass-by-reference operators (&) in JScript. Also, you can't access structure members using "rc.left" or "rc.top". I suggest you learn more about Interop and DataBloc before attempting to do such conversions.

Anyway, to get you started, I tried to convert the snippet from that thread to JScript. I didn't test whether this actually works, but it shows the principles. Have a go with it and see if you can work out the rest.

Javascript code:
var SM_CXSCREEN = 0;
var SM_CYSCREEN = 1;
 
function IsFullScreenAppRunning() {
    var hWnd = Interop.Call('user32', 'GetForegroundWindow');
 
    if(!hWnd)
        return false;
 
    if(!Interop.Call('user32', 'IsWindowVisible', hWnd) || Interop.Call('user32', 'IsIconic', hWnd) || !Interop.Call('user32', 'IsZoomed', hWnd))
        return false;
 
    var rc = Interop.Allocate(16);
    if(!Interop.Call('user32', 'GetWindowRect', hWnd, rc))
        return false;
       
    var width = rc.ReadDWORD(8) - rc.ReadDWORD(0);
    var height = rc.ReadDWORD(12) - rc.ReadDWORD(4);
 
    return (width >= Interop.Call('user32', 'GetSystemMetrics', SM_CXSCREEN) && height >= Interop.Call('user32', 'GetSystemMetrics', SM_CYSCREEN));
}


RE: RE: How to detect fullscreen application? by V@no on 11-28-2010 at 08:18 PM

Thank you.
The code some-what working, but not with every fullscreen applications. For example in some cases it still fails recognize WMP (Windows Media Player) or firefox (via F11 key), but it works fine on PotP...

P.S.
In code from the original topic seems to be bad logic when checking if window is maximized. Instead of

Javascript code:
if(!Interop.Call('user32', 'IsWindowVisible', hWnd) || Interop.Call('user32', 'IsIconic', hWnd) || !Interop.Call('user32', 'IsZoomed', hWnd))


it should be:
Javascript code:
if(!Interop.Call('user32', 'IsWindowVisible', hWnd) || Interop.Call('user32', 'IsIconic', hWnd) || Interop.Call('user32', 'IsZoomed', hWnd))



RE: How to detect fullscreen application? by Matti on 11-28-2010 at 08:52 PM

As I said, I literally converted what was in that post to JScript. I'll let you play with it and see if you can get it working the way you want. :)