Does anyone know an easy way to use SendMessage
to send a textstring from my VBprg to Starcraft?
A commented example would be nice ;)
Dim BW As Long, TXT As Long, SM As Long, CHILD, Stuff As String
If FindWindow("SWarClass", "Brood War") <> 0 Then
BW = FindWindow("SWarClass", "Brood War") 'Find hwnd of brood war window
CHILD = FindWindow("SDlgDialog", vbNullString) 'find dialog of brood war window
TXT = FindWindowEx(CHILD, 0, "Edit", vbNullString) 'find hwnd of the textbox
SM = FindWindowEx(CHILD, 0, "Button", "&Send") 'find hwnd of the send button
Stuff = "TEXT YOU WANT TO SEND" 'add the text to a string
SendMessage TXT, WM_SETTEXT, 0, ByVal Stuff 'use settext to send the text string to the textbox on brood war
SendMessage SM, BM_CLICK, 0, 0& 'use click to click the send button on brood war
End If
voila...
you really should dim CHILD as Long. Also, you have an unneeded call to FindWindow. I can't recollect how to do this in vb.. but something like this would be more efficient:
if(BW=FindWindow("SWarClass", "Brood War")) //set BW to the return value of FindWindow() then test it
{
...
}
Edit: fixed the !
thanks so very much!! you dont know how grateful i am now. i have been sitting with that problem all night. I ran another prg i downloaded from psc and found out that the sc class was called SWarClass but did not understand what that is. Can you explain a little of what SWarClass is? Also the SC window was represented by an number. I try out your example. im sure it works. i have understood how good you guys are. thanks for helping. i help back when there is a moment.
okey here is what i have done so far, but it does not seem to send the text to SC yet. thanks for your support
http://iu02.lbs.se/iu02walter/projects/sendtostarcraft/
by some reason these images on the page does not always seem to work. its screens of the same code found in the SendToSC.htm file.
The controls i have is:
text1
command1
As an help on SendKeys to others wanting to do the same in the future I post a link to an explanation i found useful:
http://www.estescentral.net/Documentation/api/ref/f/findwindowex.html
i recoqnized that the
End Sub
in the bottom of the vbcode i posted earlier is not shown. Just add it downmost in the document.
Just copy the vbcode and paste it into a new form in vb and place out 1 textbox and 1 commandbutton.
Anyone who feeling eager to solve my problem?
could just use findwindow(vbnullstring,"Brood War")
Quoteyou really should dim CHILD as Long. Also, you have an unneeded call to FindWindow. I can't recollect how to do this in vb.. but something like this would be more efficient:
if(BW=FindWindow("SWarClass", "Brood War") //set BW to the return value of FindWindow() then test it
{
...
}
Edit: fixed the !
Pfffft, you missed a closing bracket :P
lol, see what happens when you don't have an IDE.
thanks for help! problems is solved. thanks to all in vL
hey punk, i aint in vL!
okey mesiah =) thanks anyway. tonight i got help from others of vl and now its working!! you can get the vb saurce if you are interested