|
-
Jan 15th, 2008, 06:17 PM
#1
Thread Starter
Addicted Member
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
-
Jan 15th, 2008, 06:43 PM
#2
Re: Help, Getting All the ClassNames in a Window
Just a thought, have you changed the Longs to integers in the GetClassName declaration ?
Casey.
-
Jan 15th, 2008, 06:47 PM
#3
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 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 
-
Jan 15th, 2008, 09:05 PM
#4
Thread Starter
Addicted Member
Re: Help, Getting All the ClassNames in a Window
wierd.. i posted in the wrong window 
here is the code
vb Code:
Function GetWindowItems(ByVal hwi As Integer, ByVal lst As ListBox) As Integer
Dim lhndchild As Integer
Dim strclass As String
strclass = ""
lst.Items.Clear()
lhndchild = GetWindow(hwi, GW_CHILD) 'Ritrive handles of the child windows in the 'control.exe' window
Do
lhndChild = GetWindow(lhndChild, GW_HWNDNEXT) 'Get text of the fist child window
If lhndChild = 0 Then Exit Do 'IF no more child window to ritrive, then exit.
Dim MyB As New System.Text.StringBuilder("", 255)
Call GetClassName(lhndchild, strclass, 30) 'get class name of the first child window
MsgBox(strclass.Length)
'MsgBox(MyB)
lst.Items.Add(strclass)
Loop
End Function
-
Jan 16th, 2008, 06:31 PM
#5
Thread Starter
Addicted Member
Re: Help, Getting All the ClassNames in a Window
no one wants to help me
-
Jan 26th, 2008, 03:21 PM
#6
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 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 
-
Jan 26th, 2008, 03:46 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|