how can you find the state of another Windows application?

I've almost finished a screen jiggling app, to prevent managers from having their laptops lock when they're waffling for too long in a presentation, but have been thrown a spanner by the guy writing the app's spec.
Currently, I grab the active processes, and check against a list of apps which can ignore the lock out period in our group policy, e.g. WebEx and PowerPoint, and identify if they're the active window, but I can't work out how to tell if they're maximised.
(We're being as specific as we can to stop people working out certain apps will stop their laptops from locking if running in the background)

This app will primarily be used on Windows XP machines, but will need to run in Windows 7 eventually.

The code I'm using to pick up the window details is attached, and taken from

Is there a simple way to check if the active window is maximised, rather than just normal?
(I've tried isiconic but that didn't differentiate between normal and maxismised)
Private Function checkAppInFocus(ByVal curproc As String)
        Dim activeExempt As Boolean = False

        Dim hWnd As IntPtr = GetForegroundWindow()
        If hWnd <> IntPtr.Zero Then
            '—– Find the Length of the Window’s Title —– 
            Dim TitleLength As Integer
            TitleLength = GetWindowTextLength(hWnd)
            '—– Find the Window’s Title —– 
            Dim WindowTitle As String = StrDup(TitleLength + 1, "*")
            GetWindowText(hWnd, WindowTitle, TitleLength + 1)
            '—– Find the PID of the Application that Owns the Window —– 
            Dim pid As Integer = 0
            GetWindowThreadProcessId(hWnd, pid)
            If pid = 0 Then Exit Function
            '—– Get the actual PROCESS from the process ID —– 
            Dim proc As Process = Process.GetProcessById(pid)
            If proc Is Nothing Then Exit Function
            If curproc = proc.ProcessName Then activeExempt = True
            MsgBox(activeExempt.ToString, MsgBoxStyle.Exclamation)
        End If
        Return activeExempt
    End Function

Open in new window

Who is Participating?
käµfm³d 👽Commented:
There should be a dot between "InteropService" and "DllImport"  = )
käµfm³d 👽Commented:
Can't say that I've used it, but the IsZoomed API function sounds promising.

C# Signature

Converted for VB
<System.Runtime.InteropServicesDllImport("user32.dll")> _
Public Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
End Function

Open in new window

mr_nadgerAuthor Commented:
bloody marvellous!

I've spent ages trying to google this and nowhere was iszoomable mentioned!

Thank you
käµfm³d 👽Commented:
Admittedly, I found it mentioned on another forum. I subsequently searched that term in the API documentation and voila!

Glad it worked for you  = )
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.