Valhalla Legends Forums Archive | General Programming | SendMessage (from VB)

AuthorMessageTime
ioSys
Does anyone know an easy way to use SendMessage
to send a textstring from my VBprg to Starcraft?
A commented example would be nice  ;)
February 16, 2003, 9:30 PM
MesiaH
[code]
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[/code]

voila...
February 16, 2003, 11:53 PM
Etheran
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:
[code]
if(BW=FindWindow("SWarClass", "Brood War")) //set BW to the return value of FindWindow() then test it
{
...
}
[/code]

Edit: fixed the !
February 17, 2003, 12:51 AM
Walter
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.
February 17, 2003, 6:08 AM
Walter
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/
February 17, 2003, 7:36 AM
Walter
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
February 17, 2003, 7:39 AM
Walter
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
February 17, 2003, 7:43 AM
Walter
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.
February 17, 2003, 7:47 AM
ioSys
Anyone who feeling eager to solve my problem?
February 17, 2003, 3:38 PM
St0rm.iD
could just use findwindow(vbnullstring,"Brood War")
February 17, 2003, 4:57 PM
Eibro
[quote]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:
[code]
if(BW=FindWindow("SWarClass", "Brood War") //set BW to the return value of FindWindow() then test it
{
...
}
[/code]

Edit: fixed the ![/quote]
Pfffft, you missed a closing bracket :P
February 17, 2003, 5:58 PM
Etheran
lol, see what happens when you don't have an IDE.
February 17, 2003, 5:59 PM
ioSys
thanks for help! problems is solved. thanks to all in vL
February 17, 2003, 8:14 PM
MesiaH
hey punk, i aint in vL!
February 17, 2003, 10:53 PM
Walter
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
February 18, 2003, 8:10 AM

Search