entering text into another progs textbox

homebrew311

Active member
Joined
Oct 25, 2003
Messages
31
hey i wanna kno if and how u enter text into another progs textbox. ive seen other programs enter text into an AIM box and automatically send.

More specific: u have the main exec. (call it "hi"), and one that is already running ("bye"). u load up "hi". lets say hi has a textbox that when typed in, enters its text to byes textbox. how do u do this? ill repost if u dont understand. thx for the help

p.s. if possible give code in vb.net.
 
thx but i dont know how to get handles of other windows, or to send messages to that windows textbox. could someone give me an example please? im dumb with this API stuff
 
Code:
    Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
    Private Const WM_SETTEXT As Integer = &HC

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - Notepad") /// assuming you have notepad open.
        Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString)
        Dim strText As String = "some text"
        If Not x = 0 Then
            SendMessage(x, WM_SETTEXT, 256, strText)
        End If
    End Sub
 
hey thanx a lot, but heres another: wut if i made a program and i called its textbox "1xoBtxeT". would i just change the "Edit" in ur code to "1xoBtxeT"? (and the caption of course)
 
it doesnt seem to work when i try it. i make sure i get the right window title and i remember wut i named the control, but it doesnt work.
 
The name of the control has nothing to do with the Win32 windowing system. The control name is just a programmatic method of addressing an object that will ultimately be rendered as a window of class type EDIT. The code provided by dynamic_sysop should work as is.
 
you are using the modified version of SendMessage that i posted arent you? with Ansii just before the word " Function " and the ByRefs replaced by ByVals ,eg:
Code:
Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
/// " Declare Ansi Function " and " ByVal lParam As String " rather than " ByRef lParam As String "
 
The EDIT refers to the window class, not the name given in VB. When compiled, the name given by VB is lost (as far as I know, at least). You should set the classname to "WindowsForms10.EDIT.app1" and try that.
 
Just to clarify the class name for a non-.NET application text box would be "EDIT", while the class name for a .NET application text box would be "WindowsForms10.EDIT.app1".
 
thx a lot for all the input it really helps. I kno how to use the language to do a lot of practical things like designing a program that makes making web pages easier and wutnot but im still new to using the API in vb. sry if i get u guys frustrated. anyway wut if there were 15 textboxes? how would i choose, lets say, #7?
 
Reverse it

How would you do the opposite idea:

Get textbox contents from another application and put it in your own application w/out doing copy/paste w/ the mouse.


Chris
 
Back
Top