×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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.  :)

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

>>I'm in the process of teaching myself about the Win32 API

If you want to use the Win32 API then why using .NET? Wasn't .NET supposed to be OS independent?

Greetings,  
Rick

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

(OP)
Good question; I've been reading up on the Win32 API and .NET recently and it seems like .NET has evolved quite a bit for purposes of event and message handling between two .NET apps, injecting messages and such into foreign apps like I'm trying to do seems still the realm of Win32 API calls in (for lack of a better term) the "old" VB6 style.

I've managed to figure out what my problem was above, for this particular program I was trying to insert messages into, I was referencing the wrong control within the program.  

There are two Edit controls and I was sending messages to the wrong one!  Once I updated my code to reference the other it worked like a charm.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close