Results 1 to 3 of 3

Thread: Using an another window

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    1
    I am looking for a way to send keystrokes to another window. How can I do this? Any sample code?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    New Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    6
    Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
    Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
    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_SETTEXT = &HC

    SendMessage Handle, WM_SETTEXT, 0, ByVal Form1.Text1.Text

    First, you need to find the handle of the Edit Control you want to send the text to and thats where the FindWindow function comes in to play,( this function finds the appliaction you want to send the text to), next you must use the FindWindowEX to find the edit control in the that application once you have the edit control's handle you can send any string you want using the SendMessage Function.


    I've included a sample program. just copy this code into a standard project file. put a textbox and a command button on form1

    'copy this into your Module
    Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
    Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
    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_SETTEXT = &HC

    Public Function SendTEXT()
    Dim strString As String

    Dim lParent As Long
    lParent = FindWindow("Notepad", vbNullString)
    Dim lChild1 As Long
    lChild1 = FindWindowEx(lParent, 0, "Edit", vbNullString)


    SendMessage lChild1, WM_SETTEXT, 0, ByVal Form1.Text1.Text

    End Function

    'copy this into form1
    Private Sub Command1_Click()
    Call SendTEXT
    End Sub

    Private Sub Form_Load()
    Shell "C:\WINDOWS\NOTEPAD.EXE", vbNormalFocus
    End Sub

    I hope this helps and if you have any questions just email me. [email protected]


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