Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing the handle of a class within a process...

Status
Not open for further replies.

Zoplax

Technical User
Oct 2, 2002
58
US
I have a couple of VB.NET functions as follows:

Private Function EnumParentProc(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean

Dim sb As New StringBuilder(256)

GetWindowText(hWnd, sb, sb.Capacity)

Dim windowText As String = sb.ToString()

'If (windowText.ToString = "<main program>") Then
If (windowText.ToString = "<sub program within main>") Then

MsgBox(windowText.ToString)


EnumChildWindows(hWnd, ecp, IntPtr.Zero)

End If

Return True

End Function



Private Function EnumChildProc(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean

Dim className As New StringBuilder(256)

GetClassName(hWnd, className, className.Capacity)

If className.ToString.StartsWith("<class name within sub program>") Then

MsgBox(className.ToString)
MsgBox(hWnd.ToInt32)
MsgBox(lParam.ToInt32)

Dim textLength As Integer = SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero)
Dim windowText As New StringBuilder(textLength + 1)

SendMessage(hWnd, WM_GETTEXT, windowText.Capacity, windowText)

ComboBox1.Items.Add(windowText)

MsgBox(windowText.ToString)

End If
Return True

End Function



Basically, this tries to grab a handle to a class within a program. However, the issue is that there happen to be two objects with the same class name within the program, and I only want the handle of the first of these.

I'm using WinspectorSpy to spy on the objects, and according to it the one class I want has an "ID" of 100, while the one I do NOT want has an "ID" of 101.

Is there some way to not only use the ClassName, but also use the ID, so that I can pick the one of these two which I want to send messages to?

Forgive me if I'm mangling the terminology, I'm in the process of teaching myself about the Win32 API and I haven't got all the terms straight in my mind yet. I can post the entire source code I have so far if that'll help; it currently enumerates both like-named classes and shows msgboxes for each with the class name and I guess the handle (integer).

Thanks in advance for any help, I would greatly appreciate it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top