Results 1 to 8 of 8

Thread: Using SendMessage instead of SendKeys... HELP!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    6

    Angry

    I have written a program which changes text, and it can automatically send the text to a window such as AOL or another chat room.
    At the moment it uses SendKeys, well actually it puts the text on the clipboard then sends ^v {ctrl+v). However, this can cause it to crash a lot, and sometimes it sends what was previously on the clipboard.
    When I used just SendKeys to send the whole thing it crashed all the time. I have heard about SendMessage, but I do not know how to use it.
    In the API tutorial, it said SendMessage was very popular, and many people use API for AOL add-on programs. This is exactly what I want to do, but it didnt say how.
    I currently only have VB 5 Control Creation Edition. Can anyone help?

    MultiTools by Edward Millen - Beta version 1.2.0
    Includes Text Transformer
    http://members.aol.com/edwardmillen/programlink.htm Click here for more info

  2. #2
    New Member
    Join Date
    Oct 2000
    Location
    Finland
    Posts
    12
    Well... I check fast that SendMessage-function/sub from API Viewer...
    Ok...
    Code:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    So... You need hwnd of form, what is your target-form.
    We can get it with this function:
    Code:
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Just try this
    Code:
    dim ret as long
    ret = FindWindow(vbnullstring, "Window Title Text")
    Now you got target-forms hwnd in ret.
    Then you need to get id/command-list for your program...
    List includes data like this:

    Play button 40045

    "This data was from WinAmp API"
    So... You need call your program with this way:
    Code:
    Public Const WM_COPYDATA = &H4A
    Public Const WM_USER = &H400
    Public Const WM_COMMAND = &H111
    
    SendMessage ret, <WM_const>, DATA, ID 'ID is 40045 in Winamp case and DATA is vbnull.
    Without id/command-list you can not do anything.
    Only what I can tell for you, is how to control Winamp with SendMessage. I hope, that you can understand some of these text... I'm too tired just now
    GAMES, PROGRAMS, ACTIVEX CONTROLS!
    ALL, WHAT WE NEED

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    I belive you send the WM_CHar Message for each key you want to send. And put the string in the lParam, so

    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    6
    lol... thats a problem... im just reading this at 4:15am and i thought thats why i couldnt understand it! hmm... better get some sleep... then maybe ill understand it

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    6

    Smile

    hmmm..... thanks for that anyway... i got the findwindow bit going, thats pretty good... but i dunno what the last two bits on SendMessage are... this is what i tried:

    (SendWindow = "AOL", the FindWindow part works)
    Code:
    SendWindowhWnd = FindWindow(vbNullString, WindowName)
    
    SendMessage SendWindowhWnd, "Test", 13, 0
    I tried the original Data, ID one and all different numbers for those, but it always says Type Mismatch. I suppose i need something to get those numbers for the chat room window in AOL and the chat entry box. I dont have an API Viewer.

  6. #6
    Guest
    You should be sending the WM_CHAR message.
    Code:
    'This will send the letter "A" to the respective hWnd
    SendMessage HwndToSendTo, WM_CHAR, vbKeyA, 0

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    6

    Unhappy

    Originally posted by Megatron
    You should be sending the WM_CHAR message.
    Code:
    'This will send the letter "A" to the respective hWnd
    SendMessage HwndToSendTo, WM_CHAR, vbKeyA, 0
    Thats stupid!!! I have to send the whole contents of a text box, i cant do it like that!!! I know its SendMessage!

  8. #8
    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