Results 1 to 6 of 6

Thread: Obtaining the handle of a Text Box Control.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    Unhappy Obtaining the handle of a Text Box Control.

    i have tried to browse thorugh the MSDN library and the message boards to figure out how to do this, but im not having any luck. I want to be able to paste text into a text box of another window. How can I reference the handle of that box? Thanks in advance.

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Look at the code in the General forum under Net send

    http://161.58.186.97/showthread.php?s=&threadid=83852
    This tells you how to find a window, then a child window and extract the text from it,
    use these principles (and just set the text instead of extracting it)if you dont own the app, (if you do own the app then its TextBoxName.hWnd) and the message is WM_SETTEXT, and the classname for textbox is "Textbox" unless the app was written in vb then (CUE GURU) i'm sure someone knows what the classname is (try doing a forum search on "Thunder")

    hope this helps (sorry it's a bit muddled but I have to run to a meeting)
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    ....

    much appreciated.. soulds like what i was looking for. thanks!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    hmmmm...

    ok.. im trying to wite a stub now that will enumerate the child windows of a parent window I have come up with the code shown below. I'm running it on a Window I created myself and searching for a value I know should exist( i have a text box on the form called ProbDisc). It only loops once and comes up with a value of "On Top", which i assume is my always on top check box, but goes no further. Did i screw up somewhere?

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal _
    lParam As String)

    Dim lhWnd&
    Dim ltxthWnd
    Dim ltChars&
    Dim sBuff$



    Private Sub Form_Load()
    sBuff = String(256, " ")
    lhWnd = FindWindowEx(0&, 0&, vbNullString, "TaskHelper - ddddd") 'Request Detail")

    If lhWnd Then EnumChildWindows lhWnd, AddressOf EnumChildProc, 0

    End Sub

    ---------------------------------------------------------
    In a Module, we have:
    ----------------------------------------------------------
    Private Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long


    Private Const WM_GETTEXT = &HD

    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim Length As Long
    Dim sName As String
    Dim Temp As String
    Static iCount As Integer

    iCount = iCount + 1
    Length = GetWindowTextLength(hwnd) + 1

    If Length > 1 Then
    sName = Space(Length)
    GetWindowText hwnd, sName, Length
    sName = Left(sName, Length - 1)
    If sName Like "ProbDisc" Then
    MsgBox "Window Found!"
    EnumWindowsProc = 0
    Else
    MsgBox sName
    EnumWindowsProc = 1
    End If
    End If

    End Function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    dUUUHHH!

    thats what i get for cutitng and pasting too much code.. never mind guys, i think i got it.

  6. #6
    Megatron
    Guest
    VB Code:
    1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3. Private Const WM_PASTE = &H302
    4.  
    5. Private Sub Command1_Click()
    6.    
    7.     Dim hParent As Long, hChild As Long
    8.    
    9.     hParent = FindWindowEx(0, 0, "MyWindowClass", "MyWindowTitle")
    10.     hChild = FindWindowEx(hParent, 0, "Edit", vbNullString)
    11.    
    12.     SendMessage hChild, WM_PASTE, 0, 0
    13.    
    14. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width