Results 1 to 7 of 7

Thread: [RESOLVED] Getting a window's caption by its class name

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2006
    Posts
    615

    Resolved [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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2006
    Posts
    615

    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?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    2.                      ByVal lpClassName As String, _
    3.                      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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2006
    Posts
    615

    Re: Getting a window's caption by its class name

    k. here is my code
    VB Code:
    1. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2.  
    3. Private Sub Form_Load()
    4.     MsgBox FindWindow("#32770", "GRPsuper9's Buddy List Window")
    5. End Sub

    but whenever i do that, it gives me 197210 in return. how would i make it search for the username tho?

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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:
    1. Option Explicit
    2.     Private Declare Function FindWindow Lib "user32" Alias _
    3.                     "FindWindowA" (ByVal lpClassName As String, ByVal _
    4.                     lpWindowName As String) As Long
    5.     Private Declare Function GetWindowText Lib "user32" Alias _
    6.                     "GetWindowTextA" (ByVal hwnd As Long, ByVal _
    7.                     lpString As String, ByVal cch As Long) As Long
    8.  
    9. Private Sub Command1_Click()
    10.     Dim buf As String, wnd As Long
    11.         wnd = FindWindow([B]"yourClassHere"[/B], vbNullString)
    12.             If wnd Then
    13.                 buf = String(100, Chr$(0))
    14.                 GetWindowText wnd, buf, 100
    15.                 buf = Left$(buf, InStr(buf, Chr$(0)) - 1)
    16.                     MsgBox buf
    17.             Else
    18.                 MsgBox "Cant find window..."
    19.             End If
    20. End Sub
    Btw... what username are you talking about? System?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2006
    Posts
    615

    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
  •  



Click Here to Expand Forum to Full Width