• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

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
http://kellyschronicles.wordpress.com/2008/05/15/find-the-active-window-and-form-in-vb-net/

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

0
mr_nadger
Asked:
mr_nadger
  • 3
1 Solution
 
käµfm³d 👽Commented:
Can't say that I've used it, but the IsZoomed API function sounds promising.

C# Signature
http://www.pinvoke.net/default.aspx/user32.iszoomed

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

Open in new window

0
 
käµfm³d 👽Commented:
There should be a dot between "InteropService" and "DllImport"  = )
0
 
mr_nadgerAuthor Commented:
bloody marvellous!

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

Thank you
0
 
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  = )
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now