CodeItBetter Programming Another VB Programming Blog

How to check the window state of an external application

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'System & API - How to check the window state of an external application
'API Declarations to Find Parent and Child windows
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
 
Private Type POINTAPI
    x As Long
    y As Long
End Type
 
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
 
Private Type WINDOWPLACEMENT
    Length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type
 
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As Long, _
    lpwndpl As WINDOWPLACEMENT) As Long
 
Private Const SW_NORMAL As Long = 1
Private Const SW_MINIMIZE As Long = 6
Private Const SW_MAXIMIZE As Long = 3
 
Private Function GetWindowState(ByVal lhWnd As Long) As FormWindowStateConstants
    Dim winPLACE As WINDOWPLACEMENT
    winPLACE.Length = Len(winPLACE)
    GetWindowPlacement lhWnd, winPLACE
 
    Select Case winPLACE.showCmd
    Case SW_MINIMIZE
        GetWindowState = vbMinimized
    Case SW_MAXIMIZE
        GetWindowState = vbMaximized
    End Select
End Function
 
Sub main()
    Dim hMain As Long
    'To Find the Edgar Ease Main Window
    hMain = FindWindow("ee_CamsFrame", vbNullString)
    If hMain <> 0 Then Debug.Print GetWindowState(hMain)
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.