Saying lines into W:ET (Delphi 7.2)


(Donpedro) #1

Hi everybody!
I made an mp3player in Delphi, and i want it to say what am i listening. I tried to call the dll-s and call functions say print g_print-didn’t work. Somebody said on IRC, i need to use the hidden console of ET, and WIN 32 API functions, but i am too lame. I read a lot of tutorial, but didn’t find how to fill edit’s text of another applications.
Thx for the helps


(Sauron|EFG) #2

Try something like this to find the console window:


  HWND hConWin;
  HWND hCmd;

  hConWin = FindWindowEx(NULL, NULL, NULL, "ET Console");
  if(NULL == hConWin)
    return FALSE;

  if(showConsole)
    ShowWindow(hConWin, SW_SHOW); // Display the console window
  else
    ShowWindow(hConWin, SW_HIDE);

  hCmd = FindWindowEx(hConWin, NULL, "Edit", NULL);
  if(NULL == hCmd)
    return FALSE;

Then you simply send the text and a return character to the edit box:


  SendMessage(hCmd, WM_SETTEXT, NULL, (LPARAM)"say_team Hi!");
  SendMessage(hCmd, WM_CHAR, 13, 1);

You’ll have to translate from C++ to Delphi yourself, and remember that this is probably mostly annoying to the other players! (I would mute you if you did it on our server. :wink: )
Use echo instead of say or say_team to be less annoying and still see the song titles in game. :slight_smile:


(Donpedro) #3

Thx!
Seems it’s windows api as i can see, but i cant translate it into delphi cuz im lame in windows api(what a moron sentence). C mentioned he works in delphi, so i wat for a person who can tell me in delphi.


(Sauron|EFG) #4

The windows API calls should be more or less identical in Delphi (close enough that the compiler should let you sort the rest).


(Donpedro) #5

i got some errors in delphi when i inserted the code:
Undeclared identifier hconwin, hcmd
hConWin = FindWindowEx(NULL, NULL, NULL, “ET Console”): Incompatible types variant and PAnsiChar, illegal character $22


(Sauron|EFG) #6

http://www.jpgriffiths.com/tutorial/api\tutorial4.html

The handles should be declared Thandle, and try declaring a char array and using that instead of the string “ET Console”.


(Donpedro) #7

Good tutorial, but no succes :frowning:
Can you explain the lines for me?
for example:

hwnd:hconwin //Now declares blah blah


(Donpedro) #8

Succes! Thank you very much!
Here is the working Delphi code:

procedure TForm1.Button1Click(Sender: TObject);
var
HWND:thandle;
HWND2:THandle;
s:string;
begin
s:='blah';
hwnd:=Findwindow (nil, 'ET Console');
if hwnd = 0 then Showmessage ('ET is not running')
else showmessage ('ET is running');
if hwnd<> 0 then begin
showwindow (hwnd, SW_SHOW);
hwnd2:=FindWindowEx (hwnd, 0, Pchar('Edit'), nil);
SendMessage(hwnd2, WM_SETTEXT, 0, Integer(PChar(S))) ;
SendMessage(hwnd2, wm_char, 13, 0);
end;
end;

(xro) #9

Well, i used that code to send commands to the console and it works perfectly, but what if I want to read the console and save it to a log file ?

EDIT: i’ve found this: http://cheatersutopia.com/forum/showthread.php?t=6994 but i cant get it to work :frowning: any help ?