Click to See Complete Forum and Search --> : Using SendMessage instead of SendKeys... HELP!
EdwardMillen
Oct 19th, 2000, 09:05 PM
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
Niko Hujanen
Oct 20th, 2000, 04:12 PM
Well... I check fast that SendMessage-function/sub from API Viewer...
Ok...
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:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Just try this
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:
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 :)
gwdash
Oct 21st, 2000, 08:21 PM
I belive you send the WM_CHar Message for each key you want to send. And put the string in the lParam, so
EdwardMillen
Oct 21st, 2000, 10:19 PM
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
EdwardMillen
Oct 22nd, 2000, 09:39 AM
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)
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.
You should be sending the WM_CHAR message.
'This will send the letter "A" to the respective hWnd
SendMessage HwndToSendTo, WM_CHAR, vbKeyA, 0
EdwardMillen
Oct 22nd, 2000, 01:06 PM
Originally posted by Megatron
You should be sending the WM_CHAR message.
'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!
enigmaICE
Oct 22nd, 2000, 01:14 PM
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. enigma676@home.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.