Results 1 to 5 of 5

Thread: How to detect if window is open ?[resolved]

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    How to detect if window is open ?[resolved]

    Well i know how to detect if an app is running by using its caption,

    put this in a timer etc,

    VB Code:
    1. Dim WinWnd As Long
    2.  WinWnd = FindWindow(vbNullString, "app caption")

    but take the same app that has two different windows but both have the same caption, well you can identify sections(windows ?) within these windows by their handles.

    So how would i code this to detect if a window is open by deteceting a certain part within this window by it handle...lol
    Last edited by Jmacp; Mar 11th, 2004 at 04:23 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    You may try using EnumWindows api function (not qute sure but give it the shot. Here is a quick sample from allapi.net:
    VB Code:
    1. 'Add this code to a form
    2. Private Sub Form_Load()
    3.     'KPD-Team 2000
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     'Set the form's graphics mode to persistent
    7.     Me.AutoRedraw = True
    8.     'call the Enumwindows-function
    9.     EnumWindows AddressOf EnumWindowsProc, ByVal 0&
    10. End Sub
    11. 'Add this code to a module
    12. Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    13. Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    14. Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    15. Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    16.     Dim sSave As String, Ret As Long
    17.     Ret = GetWindowTextLength(hwnd)
    18.     sSave = Space(Ret)
    19.     GetWindowText hwnd, sSave, Ret + 1
    20.     Form1.Print Str$(hwnd) + " " + sSave
    21.     'continue enumeration
    22.     EnumWindowsProc = True
    23. End Function

  3. #3

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    I think you use this, which indeed finds the main window fine but doesnt seem to recognise the child window ,



    VB Code:
    1. findmain = FINDWINDOW("class in here", vbNullString)
    2. findchild = FindWindowEx(findmain, 0&, "class in here", vbNullString)


    So i have the right class of the child(from spy++) and it finds the main window fine, why wouldnt it find the child window?

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    What kind of window is it that you're looking for? What classname do you have?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    I made a typo [resolved].

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