Microsoft spy++

  • Thread starter Thread starter cyril.tiwari
  • Start date Start date
C

cyril.tiwari

Hi,


I'm looking for some vb.net sample code to get a list of Window
Captions, as shown in Microsoft Spy++, including what classes/methods
that need to be invoked.


Thanks.
 
Hi,

You could use the enumwindows api

Dim cb As CallBack

' VB.NET declaration
Public Delegate Function CallBack( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer

Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" ( _
ByVal hwnd As IntPtr) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As IntPtr, _
ByVal lpString As StringBuilder, _
ByVal cch As Integer) As Integer

Public Function MyCallBack(ByVal hwnd As IntPtr, ByVal lParam As IntPtr)
As Boolean
Dim intLen As Integer = GetWindowTextLength(hwnd) + 1
If intLen > 1 Then
Dim strText As New StringBuilder(intLen)
Try
GetWindowText(hwnd, strText, intLen)
ListBox1.Items.Add(strText.ToString)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End If
Return True
End Function


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cb = New CallBack(AddressOf MyCallBack)
EnumWindows(cb, 0)
End Sub

Ken
 
Ken,

Thanks very much. That's exactly what I was looking for.

Cyril
 
Ken,

Thanks very much. That's exactly what I was looking for.

Cyril
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top