Results 1 to 6 of 6

Thread: Unbreakable Windows

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    Exclamation Unbreakable Windows

    I need to fild out how to get the hWnd of a windows that i only know the title to like aol has the tile AmerciaOnline well i need code that would find the class name or hWnd. I know the aol classname i was just useing that as an example(aol frame 25) thank i relly need help

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    Please help

    Please

  3. #3
    Matthew Gates
    Guest
    Use the FindWindow API function.


    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    
    Private Sub Command1_Click()
    
        Dim hWin As Long
        hWin = FindWindow("aol frame25", "America Online")
        If hWin <> 0 Then
            Msgbox "AOL Is open"
        Else
            Msgbox "Cannot find AOL window"
        End If
    
    End Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    no

    i need to find out the hWnd only buy the name "America Online" not "aol fram 25" i know how to do that

  5. #5
    Matthew Gates
    Guest
    Just change this line:

    hWin = FindWindow("aol frame25", "America Online")


    To this:


    hWin = FindWindow(vbNullString, "America Online")


    The FindWindow API function can find the hWnd either way.


    hWin = FindWindow("aol frame25", "America Online")
    hWin = FindWindow(vbNullString, "America Online")
    hWin = FindWindow("aol frame25", vbNullString)

    As long as one of them is there and the window exists, than you can receieve the handle.

  6. #6
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    Actually, I prefer FindWindowEx for all my window-finding needs. With FindWindow(Ex) all of the parameter are optional. If you leave one out, the function ignores it. However, with the API, you can't, persay, just leave the value out, like you can with MsgBox, and setting it to a zero-length string (aka: "" ) won't help either. To get findWindow(Ex) to ignore a string parameter, pass vbNullString (this is a constant, that is DO NOT USE QUOTES) to it like so:
    Code:
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
        ByVal hWndParent As Long, _
        ByVal hWndFindLast As Long, _
        ByVal lpWindowClass As String, _
        ByVal lpWindowName As String) As Long
    
    Function FindWindowByCaption&(sCaption$)
        FindWindowByCaption& = FindWindowEx(0, 0, vbNullString, sCaption)
    End Function
    Before anybody tells me that I should have just used FindWindow, well, most of my applications that use FindWindow also end up needing to use FindWindowEx. I find that if you need them both (and chances are, this app will) then you can get rid of FindWindow and make the compiled exe that much smaller.

    BTW, if you are making an AOL app (who here hasn't at least attempted one...) keep in mind that on some systems, the AOL caption is "America Online Provided by ABC Gum Corporation" and using "America Online" as the parameter will return 0.

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