Jump to content

Full screen detection


Recommended Posts

Possibly something like this?

MsgBox (0, "", _IsFullScreen ())
Func _IsFullScreen ()
    Local $hwnd = WinGetHandle ("[ACTIVE]")
    Local $aWinRect = WinGetPos ($hwnd)
    If ($aWinRect[2] >= @DesktopWidth) Or ($aWinRect[3] >= @DesktopHeight) Then Return True
    Return False
EndFunc

Cheers,

Brett

Link to comment
Share on other sites

This might be another option too.

Sleep (3000)
MsgBox (0, "", _IsFullScreen (ProcessExists ("firefox.exe")))
Func _IsFullScreen ($pid)
    Local $array = _ProcessGetHWnd ($pid, 2)
    If @error Then Return -1
    For $i = 1 to $array[0][0]
        $aWinRect = WinGetPos ($array[0][1])
        If ($aWinRect[2] >= @DesktopWidth) Or ($aWinRect[3] >= @DesktopHeight) Then Return True
    Next
    Return False
EndFunc

;===============================================================================
;
; Function Name:    _ProcessGetHWnd
; Description:    Returns the HWND(s) owned by the specified process (PID only !).
;
; Parameter(s):  $iPid      - the owner-PID.
;                   $iOption    - Optional : return/search methods :
;                       0 - returns the HWND for the first non-titleless window.
;                       1 - returns the HWND for the first found window (default).
;                       2 - returns all HWNDs for all matches.
;
;                  $sTitle      - Optional : the title to match (see notes).
;                   $iTimeout   - Optional : timeout in msec (see notes)
;
; Return Value(s):  On Success - returns the HWND (see below for method 2).
;                       $array[0][0] - number of HWNDs
;                       $array[x][0] - title
;                       $array[x][1] - HWND
;
;                  On Failure   - returns 0 and sets @error to 1.
;
; Note(s):          When a title is specified it will then only return the HWND to the titles
;                   matching that specific string. If no title is specified it will return as
;                   described by the option used.
;
;                   When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;                   often it should wait before attempting another time to get the HWND.
;
;
; Author(s):        Helge
;
;===============================================================================
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    
    While 1
        
    ; Get list of windows
        $aWin = WinList($sTitle)
        
    ; Searches thru all windows
        For $i = 1 To $aWin[0][0]
            
        ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                
            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                
            ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
                EndIf
            EndIf
        Next
        
    ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
        
    ; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop
        
    ; Waits before new attempt
        Sleep(Opt("WinWaitDelay"))
    WEnd
    
    
; No matches
    SetError(1)
    Return 0
EndFunc  ;==>_ProcessGetHWnd
Link to comment
Share on other sites

Dang, Brett... all about the hard way!

If BitAND(WinGetState(WinGetHandle("[ACTIVE]")), 32) Then 
    ConsoleWrite("Maximized" & @LF)
Else
    ConsoleWrite("Not Maximized" & @LF)
EndIf

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Dang, Brett... all about the hard way!

If BitAND(WinGetState(WinGetHandle("[ACTIVE]")), 32) Then 
    ConsoleWrite("Maximized" & @LF)
Else
    ConsoleWrite("Not Maximized" & @LF)
EndIf

:mellow:

Of course!

:(

Link to comment
Share on other sites

Link to comment
Share on other sites

But couldn't you also technically have a window that is not "maximized" but takes the full screen? just for argument sake.

Yes, but then WinGetState() would not have bit 5 set, which is why that is a better test of if it is maximized.

Now, if you just want to know if it covers all or most of the screen, your definitions get fuzzy. What if it's 1 pixel width smaller that the screen? Want to call that maximized, or not?

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

For that you could detect the monitor size and see if the the window size is as big or larger right?

Yea, I think that's what BrettF's script does.

Now, if you just want to know if it covers all or most of the screen, your definitions get fuzzy. What if it's 1 pixel width smaller that the screen? Want to call that maximized, or not?

I guess my question is can a window/app be Full Screen (which I am defining as 0,0 to DesktopWidth,DesktopHeigth of a monitor) without being in the state of Maximized? Seems to be it can. For example, I have a transparent gui that changes color and fills the screen, yet it is not maximized; and thus would fail to be determined as Full Screen by PsaltyDS' method. Perhaps both can be incorporated into each other. If IsMaximized or IsFullscreen.

I think, (maybe) MSN Messenger is defining a Full Screen app as an app that fills the entire desktop space and does not have a titlebar.

Edited by spudw2k
Link to comment
Share on other sites

I guess my question is can a window/app be Full Screen (which I am defining as 0,0 to DesktopWidth,DesktopHeigth of a monitor) without being in the state of Maximized? Seems to be it can. For example, I have a transparent gui that changes color and fills the screen, yet it is not maximized; and thus would fail to be determined as Full Screen by PsaltyDS' method. Perhaps both can be incorporated into each other. If IsMaximized or IsFullscreen.

Part of the problem with your definition is that the true maximized state for a window changes things you are not accounting for. The window control icon changes at the top/right of the window, the window will dynamically resize if the desktop size changes, and it will also resize if the taskbar changes size. All the drag handles at the edges and corners go away.

None of those things are true of window that is only the same size as the desktop, but not truly maximized.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Part of the problem with your definition is that the true maximized state for a window changes things you are not accounting for. The window control icon changes at the top/right of the window, the window will dynamically resize if the desktop size changes, and it will also resize if the taskbar changes size. All the drag handles at the edges and corners go away.

None of those things are true of window that is only the same size as the desktop, but not truly maximized.

:mellow:

Nevermind, I think we're just going in circles. thanks

edit:

Final thought

Is it possible to detect if a process is full screen ? Just like how MSN Messenger does, it set your status to AWAY when it detects a full screen application ..

I don't believe MSN Messenger sets your status away when you, let's say, browse the web with a maximized window. Edited by spudw2k
Link to comment
Share on other sites

Link to comment
Share on other sites

That very well could be, or perhaps is looks for specific controls that are typically full screen.

All MSN has to do is the equivalent of:
; Get handle to MSN window
$hMSN = WinGetHandle("MSN - Messenger")

; Get handle of currently active window
$hActive = WinGetHandle("[ACTIVE]")

; Test if different window is active and maximized
If ($hActive <> $hMSN) And BitAND(WinGetState($hActive), 32) Then

    ; Set 'away' condition...
        
EndIf

I don't see why it would be any more complicated than that.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

All MSN has to do is the equivalent of:

; Get handle to MSN window
$hMSN = WinGetHandle("MSN - Messenger")

; Get handle of currently active window
$hActive = WinGetHandle("[ACTIVE]")

; Test if different window is active and maximized
If ($hActive <> $hMSN) And BitAND(WinGetState($hActive), 32) Then

; Set 'away' condition...
        
EndIf

I don't see why it would be any more complicated than that.

:mellow:

Going back to the start of the post. He wants to know how MSN messenger detects a fullscreen app and sets his status to busy/away. This does not get set just because another window is active and Maximized, but only for certain fullscreen scenarios. For example. By your method, having a IE browser (or app for that manner) in a maximized state will trigger the "away condition" which is not what MSN does. Does that make sense? Not every maximized window sets the messenger state to busy/away.
Link to comment
Share on other sites

Going back to the start of the post. He wants to know how MSN messenger detects a fullscreen app and sets his status to busy/away. This does not get set just because another window is active and Maximized, but only for certain fullscreen scenarios. For example. By your method, having a IE browser (or app for that manner) in a maximized state will trigger the "away condition" which is not what MSN does. Does that make sense? Not every maximized window sets the messenger state to busy/away.

It does what I understood the description by the OP to be:
...it set your status to AWAY when it detects a full screen application ..

I don't use MSN so the details are lost on me. You didn't give an example of when it does set 'AWAY' for a full screen app.

Whatever the other conditions are, I'll wager they are just as easily implemented as what I posted.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...