Results 1 to 4 of 4

Thread: [RESOLVED] Find window state of another application

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Resolved [RESOLVED] Find window state of another application

    Hi,

    I would like to find whether another application (third party application) is in which state?

    Whether it is hidden or minimized or maximized or normal, etc.

    Thanks in advance.
    CS

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Find window state of another application

    There may be other ways, but this should work:

    VB Code:
    1. Private Type POINTAPI
    2.     x As Long
    3.     y As Long
    4. End Type
    5.  
    6. Private Type RECT
    7.     Left As Long
    8.     Top As Long
    9.     Right As Long
    10.     Bottom As Long
    11. End Type
    12.  
    13. Private Type WINDOWPLACEMENT
    14.     Length As Long
    15.     flags As Long
    16.     showCmd As Long
    17.     ptMinPosition As POINTAPI
    18.     ptMaxPosition As POINTAPI
    19.     rcNormalPosition As RECT
    20. End Type
    21.  
    22. Private Declare Function GetWindowPlacement Lib "user32" ( _
    23.                 ByVal hWnd As Long, _
    24.                 lpwndpl As WINDOWPLACEMENT) As Long
    25.  
    26. Private Const SW_NORMAL As Long = 1
    27. Private Const SW_MINIMIZE As Long = 6
    28. Private Const SW_MAXIMIZE As Long = 3
    29.  
    30. Private Function GetWindowState(ByVal lhWnd As Long) As FormWindowStateConstants
    31.     Dim winPLACE As WINDOWPLACEMENT
    32.     winPLACE.Length = Len(winPLACE)
    33.     GetWindowPlacement lhWnd, winPLACE
    34.    
    35.     Select Case winPLACE.showCmd
    36.         Case SW_MINIMIZE
    37.             GetWindowState = vbMinimized
    38.         Case SW_MAXIMIZE
    39.             GetWindowState = vbMaximized
    40.     End Select
    41. End Function

  3. #3
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: Find window state of another application

    Ok, I am a little late for this question, I know...
    But it might help all, who find this thead via a web search.

    Quote Originally Posted by bushmobile View Post
    There may be other ways
    Yes, the most simple way would probably to use following API functions:
    Code:
    Private Declare Function IsZoomed Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function IsIconic Lib "user32.dll" (ByVal hWnd As Long) As Long

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] Find window state of another application

    Yet another way is by checking the Window Style bits:

    Code:
    Private Const GWL_STYLE   As Long = (-16&)      'Retrieves the window styles.
    Private Const WS_MAXIMIZE As Long = &H1000000   'The window is initially maximized.
    Private Const WS_MINIMIZE As Long = &H20000000  'The window is initially minimized.
    Private Const WS_VISIBLE  As Long = &H10000000  'The window is initially visible.
    
    Private Declare Function GetWindowLongW Lib "user32.dll" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    
    Private Function IsIconic(ByVal hWnd As Long) As Boolean
        IsIconic = ((GetWindowLongW(hWnd, GWL_STYLE) And WS_MINIMIZE) = WS_MINIMIZE)
    End Function
    
    Private Function IsWindowVisible(ByVal hWnd As Long) As Boolean
        IsWindowVisible = ((GetWindowLongW(hWnd, GWL_STYLE) And WS_VISIBLE) = WS_VISIBLE)
    End Function
    
    Private Function IsZoomed(ByVal hWnd As Long) As Boolean
        IsZoomed = ((GetWindowLongW(hWnd, GWL_STYLE) And WS_MAXIMIZE) = WS_MAXIMIZE)
    End Function
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width