• Welcome to Valhalla Legends Archive.
 

SendMessage (from VB)

Started by ioSys, February 16, 2003, 03:30 PM

Previous topic - Next topic

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  ;)

Mesiah / haiseM

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...
]HighBrow Innovations
Coming soon...

AIM Online Status: 

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:
if(BW=FindWindow("SWarClass", "Brood War")) //set BW to the return value of FindWindow() then test it
{
...
}

Edit: fixed the !

Walter

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

Walter

#4
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/

Walter

#5
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

Walter

#6
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

Walter

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

ioSys

#8
Anyone who feeling eager to solve my problem?

Banana fanna fo fanna

#9
could just use findwindow(vbnullstring,"Brood War")

Eibro

#10
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
Eibro of Yeti Lovers.

Etheran

#11
lol, see what happens when you don't have an IDE.

ioSys

#12
thanks for help! problems is solved. thanks to all in vL

Mesiah / haiseM

#13
hey punk, i aint in vL!
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Walter

#14
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