[RESOLVED] Getting a window's caption by its class name
hey.
i was wondering if anyone could help me out on getting a window's caption. the thing is, i dont want to search just for the caption. so the caption has to be inside a specific class and search for that caption within that class. Heres the info
Window's Caption: GRPsuper9's Buddy List Window
Class Name: #32770
First thing is first, getting the whole caption out of the class name. then, i want it to get the username before the "'s Buddy List Window". in this case, GRPsuper9. but lets say i log in with Master, i want it to get master instead of grpsuper9.
can anyone help? if u need clairifcations, just post
Re: Getting a window's caption by its class name
Use FindWindow API. You can pass the classname and/or window caption. If you dont know what the caption will be then passing the classname along with vbNullstring will get the first window handle that matches. Then using GetWindowText passing the handle will get the caption.
Re: Getting a window's caption by its class name
i tried searching for the code. but since i dont understand api, i dont know which 1 to look @. can you post some code in here that would help my case?
Re: Getting a window's caption by its class name
Sounds like you dont have an API viewer so if you go over to allapi.net and download the API Viewer utility you will have them all and there is a definition and code exmple for FindWindow there too.
VB Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Re: Getting a window's caption by its class name
k. here is my code
VB Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
MsgBox FindWindow("#32770", "GRPsuper9's Buddy List Window")
End Sub
but whenever i do that, it gives me 197210 in return. how would i make it search for the username tho?
Re: Getting a window's caption by its class name
That's because FindWindow() API returns a Long data type.
Here's a way if you know the class name:
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal _
lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Dim buf As String, wnd As Long
wnd = FindWindow([B]"yourClassHere"[/B], vbNullString)
If wnd Then
buf = String(100, Chr$(0))
GetWindowText wnd, buf, 100
buf = Left$(buf, InStr(buf, Chr$(0)) - 1)
MsgBox buf
Else
MsgBox "Cant find window..."
End If
End Sub
Btw... what username are you talking about? System?
Re: Getting a window's caption by its class name
no, AIM username. Aol Instant Messanger. www.aim.com. thanks btw. ill try it out :)