Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1533
  • Last Modified:

Find a Childwindow using API in VB.NET

I am going to be using the SendMessage API call  to send keystrokes to an inactive window.  I need to be able to run a test on the application I am sending the keystrokes to, to find out the childwindow handle or name so that sendmessage will work correctly.  I have run tests with Notepad and it works great, but that is because I know to send it to the "edit" window.  This is an old database application, and I just need to find out the name of the window that contains all the fields to send keystrokes to.  So that being said, I am trying to use the GetWindow API call to find the name of the window by enumerating all the windows and sending the count and name of the window to a text box.  I keep getting errors trying to use the word "Buffer" from VB6 in .NET.  Any ideas?  This is what I have so far:

Declare Function EnumChildWindows Lib "user32" (ByVal hwndParent As Integer, ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer

Private Sub btGetWindows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btGetWindows.Click
   'Here is where I need to call the ENumProc

End Sub

Public Function EnumChildProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
        Dim slength As Short, wintext As String  ' window title text length and buffer
        Dim retval As Integer  ' return value
        Static winnum As Integer  ' counter keeps track of how many windows have been enumerated
       
        winnum = winnum + 1  ' one more window enumerated....
        slength = GetWindowTextLength(hwnd) + 1  ' get length of title bar text
        Buffer = Space(slength)  ' make room in the buffer   ******Buffer is VB6, don't know what to use for .NET******
        retval = GetWindowText(hwnd, Buffer, slength)  ' get title bar text
        txtwindows.text = "window#" &  winnum &  " " & Left(Buffer, slength - 1)) & vbcrlf & txtwindows.text ' display number of enumerated window &  display title bar text of enumerated window

        EnumChildProc = 1  ' nonzero return value means continue enumeration
 End Function

0
bengelhart
Asked:
bengelhart
1 Solution
 
iHadiCommented:
Sorry for the late response. I've posted the code here before I saw this question

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21842805.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now