Sign in to follow this  
Followers 0
CiVQ

Determine whether a fullscreen process exists

6 posts in this topic

#1 ·  Posted (edited)

Hello,

my problem is: how to determine, whether a fullscreen process exists?

It could be any game (I think it's a directx thing), or an Alt+Enter-ed console window, playing vdeo or any other, which I can't imagine :)

Anyways, I need this, because I want to write a script, which gets to suspend state, if a process claims the whole screen (not windowed).

Any suggestions?

Civ.

Edited by CiVQ

I know that my code is ugly. But it works. Mostly.

Share this post


Link to post
Share on other sites



Enumerate all visible windows and check their sizes.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

maybe this can do?

Local $var = WinList()

For $i = 1 To $var[0][0]
    ; Only check visble and maximized windows that have a title
    If BitAND( WinGetState ( $var[$i][1] ),32)  And IsVisible($var[$i][0]) Then
        ConsoleWrite("windows " & $var[$i][0] & " is MAXIMIZED" & @CRLF)
    EndIf
Next

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc   ;==>IsVisiblE

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

From the help file.

Local $var = WinList()

For $i = 1 To $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
    EndIf
Next

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc   ;==>IsVisible

Simply change line

If BitAND(WinGetState($handle), 2) Then

to

If BitAND(WinGetState($handle), 32) Then

Of course this checks for maximized windows.. Not sure how this will handle fullscreen

Share this post


Link to post
Share on other sites

@UEZ: Thans. With your idea, I have managed to brew a function.

@PincoPanco and NewPlaza: Thanks to you, too, I will chew on your advices. Sigh, I am prone to overlooking important things... :closedeyes:

 

Surprisingly, there are three (or sometimes more) fullscreen windows.

One is the Program Manager,

other two are for the currently maximized (but not fullscreen) window (which can be the Program Manager, too),

and, lastly, one is for the actually fullscreen window (like fullscreen video player or game, etc.)

Anyways, it's hearthening to see, what I write in n lines of code, the same can be achieved (with style) in n/3-4 lines of code. :D

Thanks, Civ.


I know that my code is ugly. But it works. Mostly.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@PincoPanco and NewPlaza: I've tested the code, and with flag 32 it really lists all windows which are either maximized or fullscreen.

That means, that the code has to sort out the results by window size (as UEZ suggested).

The sleep lets you to quickly "fullscreenize" one of your programs.

#include <Process.au3>
#include <Array.au3>

Sleep(5000)

Local $aFullScreens = _ProcessFullScreenGet()
If @error Then
    MsgBox(16, "_ProcessFullScreenGet", "Some error occurred. Error: "&@error)
ElseIf IsArray($aFullScreens) Then
    _ArrayDisplay($aFullScreens)
Else
    MsgBox(16, "_ProcessFullScreenGet", "Some unknown error occurred.")
EndIf


; Name...........: _ProcessFullScreenGet
; Description ...: Lists all fullscreen processes
; Syntax.........: _ProcessFullScreenGet()
; Parameters ....: none
; Return values .: Success - Returns an one-based, 4 column array of the currently FullScreen process:
;                     $aRet[0][0] - Number of rows in the array (should be 1)
;                     $aRet[x][0] - Window title
;                     $aRet[x][1] - Window handle
;                     $aRet[x][2] - Window's parent process name
;                     $aRet[x][3] - Window's parent process ID
;                  Failure - False, sets @error to:
;                  |1 - FullScreen process not found
;                  |2 - Couldn't load window list
;                  |3 - Couldn't load window dimensions
;                       @extended is set to window handle
;                  |4 - Couldn't get window's parent process ID
;                       @extended is set to window handle
;                  |5 - Couldn't get process name from its PID
;                       @extended is set to process ID
; Author ........: CiVQ
Func _ProcessFullScreenGet()
    Local $aWinPos
    Local $aWindows = WinList()
    Local $aFullScreenWinTitles[1] = [0]
    Local $aFullScreenWinHandles[1] = [0]
    Local $aFullScreenProcNames[1] = [0]
    Local $aFullScreenPIDs[1] = [0]
    Local $aRet[1] = [0]
    Local $iPID = 0
    Local $szProcessName = ""

    $aWindows = WinList()
    If @error Then Return SetError(2, 0, False)

    For $i = 1 To $aWindows[0][0]

        $aWinPos = WinGetPos($aWindows[$i][1])
        If @error Then Return SetError(3, $aWindows[$i][1], False)

        $iPID = WinGetProcess($aWindows[$i][1])
        If @error Then Return SetError(4, $aWindows[$i][1], False)

        $szProcessName = _ProcessGetName($iPID)
        If @error Then Return SetError(5, $iPID, False)


        If ($szProcessName <> "explorer.exe") And _
                ($aWinPos[3] = @DesktopHeight) And _
                ($aWinPos[2] = @DesktopWidth) And _
                ($aWindows[$i][0] <> "") Then

            _ArrayAdd($aFullScreenWinTitles, $aWindows[$i][0])
            _ArrayAdd($aFullScreenWinHandles, $aWindows[$i][1])
            _ArrayAdd($aFullScreenPIDs, $iPID)
            _ArrayAdd($aFullScreenProcNames, $szProcessName)
            $aFullScreenWinHandles[0] += 1
        EndIf
    Next

    If $aFullScreenWinHandles[0] = 0 Then Return SetError(1, 0, False)

    ReDim $aRet[$aFullScreenWinHandles[0] + 1][4]

    For $i = 1 To $aFullScreenWinHandles[0]
        $aRet[$i][0] = $aFullScreenWinTitles[$i]
        $aRet[$i][1] = $aFullScreenWinHandles[$i]
        $aRet[$i][2] = $aFullScreenProcNames[$i]
        $aRet[$i][3] = $aFullScreenPIDs[$i]
    Next

    $aRet[0][0] = $aFullScreenWinHandles[0]

    Return $aRet
EndFunc   ;==>_ProcessFullScreenGet

Edit: Error handling and filtering. Now it lists the only fullscreen process, or throws @error, if not found.

Edited by CiVQ

I know that my code is ugly. But it works. Mostly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0