Results 1 to 7 of 7

Thread: Help, Getting All the ClassNames in a Window

  1. #1

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Help, Getting All the ClassNames in a Window

    Hi Guys,

    Just got this problem right now. I am trying to create a application where in

    1. when I click the a button all the active windows in the desktop will be listed in a listbox with their window texts (Done)
    2. When I select 1 from them and click another button, all the object classnames in that form will be listed in to another list box (not done)

    My problem is that the GetClassName API is not working in VB.NET 2008. I don't know why but I am getting a blank strings. I tried it in VB6 and it works fine.

    Can any one help me





    =============
    ..code masters..

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Help, Getting All the ClassNames in a Window

    Just a thought, have you changed the Longs to integers in the GetClassName declaration ?

    Casey.

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

    Re: Help, Getting All the ClassNames in a Window

    Use the API Viewer utility (link in my signature) and set its format to VB.NET. Much easier.

    Then if your still getting issues post your code.
    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

  4. #4

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: Help, Getting All the ClassNames in a Window

    wierd.. i posted in the wrong window

    here is the code

    vb Code:
    1. Function GetWindowItems(ByVal hwi As Integer, ByVal lst As ListBox) As Integer
    2.         Dim lhndchild As Integer
    3.         Dim strclass As String
    4.         strclass = ""
    5.         lst.Items.Clear()
    6.         lhndchild = GetWindow(hwi, GW_CHILD) 'Ritrive handles of the child windows in the 'control.exe' window
    7.  
    8.         Do
    9.             lhndChild = GetWindow(lhndChild, GW_HWNDNEXT) 'Get text of the fist child window
    10.  
    11.             If lhndChild = 0 Then Exit Do 'IF no more child window to ritrive, then exit.
    12.             Dim MyB As New System.Text.StringBuilder("", 255)
    13.  
    14.             Call GetClassName(lhndchild, strclass, 30) 'get class name of the first child window
    15.             MsgBox(strclass.Length)
    16.             'MsgBox(MyB)
    17.             lst.Items.Add(strclass)
    18.  
    19.         Loop
    20.     End Function





    =============
    ..code masters..

  5. #5

    Thread Starter
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: Help, Getting All the ClassNames in a Window

    no one wants to help me





    =============
    ..code masters..

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

    Re: Help, Getting All the ClassNames in a Window

    No its not that, its just hard to work with a program we dont have.

    Your code looks ok but can you give more description of where its going instead?
    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

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: Help, Getting All the ClassNames in a Window

    using EnumWindows in .NET is easy, but you must consider that you can't use the AddressOf in the same way as in vb6, so you need to assign a Delegate to handle it.
    here's an example i quickly put together for you, it basically grabs all the windows & lists there names & window text ( if they have window text ) in this case in a listview.
    Code:
    Public Class Form1
    
        '/// modify the 1st arguement of EnumWindows to ByVal lpEnumFunc As winproc
        Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As winproc, ByVal lParam As Int32) As Int32
        Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wCmd As Int32) As IntPtr
        Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Int32) As Int32
        Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Int32) As Int32
        '/// this will handle the AddressOf issues when using .NET...
        Private Delegate Function winproc(ByVal hwnd As IntPtr, ByVal lparam As Int32) As Int32
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim proc As New winproc(AddressOf ReturnEnumProc)
    
            EnumWindows(proc, &H0)
        End Sub
    
        Private Function ReturnEnumProc(ByVal hwnd As IntPtr, ByVal lparam As Int32) As Int32
            Dim sBuilderName As New System.Text.StringBuilder(255)
            Dim sBuilderText As New System.Text.StringBuilder(255)
    
            GetClassName(hwnd, sBuilderName, 255)
            GetWindowText(hwnd, sBuilderText, 255)
    
            Dim lvi As New ListViewItem(sBuilderName.ToString)
            lvi.SubItems.Add(sBuilderText.ToString)
    
            ListView1.Items.Add(lvi)
    
            Return 1
        End Function
    End Class
    hope it helps
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

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