how can you find the state of another Windows application?

Posted on 2011-10-26
Last Modified: 2012-05-12
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

Question by:mr_nadger
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    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

    LVL 74

    Accepted Solution

    There should be a dot between "InteropService" and "DllImport"  = )
    LVL 7

    Author Closing Comment

    bloody marvellous!

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

    Thank you
    LVL 74

    Expert Comment

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

    Glad it worked for you  = )

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Xamarin 10 19
    shortcuts on desktops 14 25
    get the maximum value on a condition 3 30
    DataGridView 2 14
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now