Results 1 to 6 of 6

Thread: Textbox handle

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    France
    Posts
    5

    Smile

    Hi,

    I would like to edit a textbox, but I don't know how to
    get its handle.

    Should I use SendMessage ?

    Thanks for your answers.

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Code:
    dim Handle as long
    Handle=Text1.Hwnd

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    France
    Posts
    5

    Arrow

    Thanks oetje,

    But the Window I would edit is not one of my VB program.
    It's a Window from another program, and I want to write a
    text in one of its textbox.

  4. #4
    Guest
    Use FindWindowEx. This example will send the A key to Notepad. (so make sure Notepad is pre-opened)
    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const WM_CHAR = &H102
    
    Private Sub Command1_Click()
    
        Dim hParent As Long
        Dim hChild As Long
        
        'Get the hWnd of parent window
        hParent = FindWindow("Notepad", vbNullString)
        'Get the hWnd of the Edit Control
        hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
        'Send the "A" key to it
        Call SendMessage(hChild, WM_CHAR, vbKeyA, 0)
        
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    France
    Posts
    5

    Thumbs up

    I didn't exactly know if I had to use the parent window,
    now it's ok for me.

    Thank for your help.


  6. #6
    Guest
    Specifing the parent window will narrow it down. If you don't specify the parent window, it will just use desktop window.

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