Valhalla Legends Archive

Programming => General Programming => Topic started by: ioSys on February 16, 2003, 03:30 PM

Title: SendMessage (from VB)
Post by: ioSys on February 16, 2003, 03:30 PM
Does anyone know an easy way to use SendMessage
to send a textstring from my VBprg to Starcraft?
A commented example would be nice  ;)
Title: Re: SendMessage (from VB)
Post by: Mesiah / haiseM on February 16, 2003, 05:53 PM
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...
Title: Re: SendMessage (from VB)
Post by: Etheran on February 16, 2003, 06:51 PM
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 !
Title: Re: SendMessage (from VB)
Post by: Walter on February 17, 2003, 12:08 AM
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.
Title: Re: SendMessage (from VB)
Post by: Walter on February 17, 2003, 01:36 AM
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/
Title: Re: SendMessage (from VB)
Post by: Walter on February 17, 2003, 01:39 AM
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
Title: Re: SendMessage (from VB)
Post by: Walter on February 17, 2003, 01:43 AM
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
Title: Re: SendMessage (from VB)
Post by: Walter on February 17, 2003, 01:47 AM
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.
Title: Re: SendMessage (from VB)
Post by: ioSys on February 17, 2003, 09:38 AM
Anyone who feeling eager to solve my problem?
Title: Re: SendMessage (from VB)
Post by: Banana fanna fo fanna on February 17, 2003, 10:57 AM
could just use findwindow(vbnullstring,"Brood War")
Title: Re: SendMessage (from VB)
Post by: Eibro on February 17, 2003, 11:58 AM
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
Title: Re: SendMessage (from VB)
Post by: Etheran on February 17, 2003, 11:59 AM
lol, see what happens when you don't have an IDE.
Title: Re: SendMessage (from VB)
Post by: ioSys on February 17, 2003, 02:14 PM
thanks for help! problems is solved. thanks to all in vL
Title: Re: SendMessage (from VB)
Post by: Mesiah / haiseM on February 17, 2003, 04:53 PM
hey punk, i aint in vL!
Title: Re: SendMessage (from VB)
Post by: Walter on February 18, 2003, 02:10 AM
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