|
-
Apr 28th, 2001, 04:21 PM
#1
Thread Starter
Hyperactive Member
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
-
Apr 28th, 2001, 04:31 PM
#2
Thread Starter
Hyperactive Member
-
Apr 28th, 2001, 04:46 PM
#3
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
-
Apr 28th, 2001, 05:12 PM
#4
Thread Starter
Hyperactive Member
no
i need to find out the hWnd only buy the name "America Online" not "aol fram 25" i know how to do that
-
Apr 28th, 2001, 05:28 PM
#5
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.
-
Apr 28th, 2001, 05:46 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|