|
-
Dec 1st, 2006, 11:43 PM
#1
Thread Starter
Fanatic Member
[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
-
Dec 1st, 2006, 11:45 PM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 2nd, 2006, 12:08 AM
#3
Thread Starter
Fanatic Member
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?
-
Dec 2nd, 2006, 12:33 AM
#4
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 2nd, 2006, 06:54 PM
#5
Thread Starter
Fanatic Member
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?
-
Dec 2nd, 2006, 07:41 PM
#6
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?
-
Dec 2nd, 2006, 11:31 PM
#7
Thread Starter
Fanatic Member
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
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
|