Thread View: alt.comp.borland-delphi
4 messages
4 total messages
Started by 0BIT
Mon, 14 Apr 2003 14:10
Howto send messages to programs
Author: 0BIT
Date: Mon, 14 Apr 2003 14:10
Date: Mon, 14 Apr 2003 14:10
38 lines
2294 bytes
2294 bytes
How do I send messages to other programs ?
i've tried this:
procedure TForm1.FormCreate(Sender: TObject);
var
processInfo : TProcessInformation;
start : TStartUpInfo;
Apprunning : DWord;
begin
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
if
CreateProcess(nil,'notepad.exe',nil,nil,true,0,nil,nil,start,processInfo)
then begin
******** i think the handle is wrong ?
SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
ShowMessage('send close message ?');
SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until Apprunning <> WAIT_TIMEOUT;
ShowMessage('closehandles?');
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
ShowMessage('done');
end else
ShowMessage('failed');
end;
Thnks in advance,
0BIT
Re: Howto send messages to programs
Author: Maynard Philbrook
Date: Mon, 14 Apr 2003 15:57
Date: Mon, 14 Apr 2003 15:57
48 lines
2750 bytes
2750 bytes
Yes you are correct, it is wrong!
:)
the process and thread handles are not what you want.
you need the window handle that has been created from one of the
threads
Look at the EnumThreadWindows to get a list of windows created
from that thread..
0BIT wrote:
> How do I send messages to other programs ?
>
> i've tried this:
>
> procedure TForm1.FormCreate(Sender: TObject);
> var
> processInfo : TProcessInformation;
> start : TStartUpInfo;
> Apprunning : DWord;
> begin
> FillChar(Start,Sizeof(Start),#0);
> start.cb := SizeOf(start);
> if
> CreateProcess(nil,'notepad.exe',nil,nil,true,0,nil,nil,start,processInfo)
> then begin
>
> ******** i think the handle is wrong ?
> SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
> ShowMessage('send close message ?');
> SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
>
> repeat
> Apprunning := WaitForSingleObject
> (ProcessInfo.hProcess,100);
> Application.ProcessMessages;
> until Apprunning <> WAIT_TIMEOUT;
>
> ShowMessage('closehandles?');
> CloseHandle(ProcessInfo.hProcess);
> CloseHandle(ProcessInfo.hThread);
> ShowMessage('done');
> end else
> ShowMessage('failed');
> end;
>
> Thnks in advance,
> 0BIT
Re: Howto send messages to programs
Author: 0BIT
Date: Tue, 15 Apr 2003 11:52
Date: Tue, 15 Apr 2003 11:52
103 lines
4160 bytes
4160 bytes
Tnks for your code !!
The WM_CLOSE message works, now I want to send a string to notepad.
I tried this:
SendMessage(NoteBookHandle,WM_CHAR,Ord('A'),0);
I thought the char 'A' should appear in the program, but it doesn't ?
Do I need another window handle for this ?
Greetings,
0BIT
"DonDan" <oneofthecritics@hotmail.com> wrote in message
news:3e9adbb2$1$37566$91cee783@newsreader02.highway.telekom.at...
> SendMessage requires the handle of
> the destination window NOT the processID.
> You can use this function to get the handle
> using the processID.
> (in your case insert:
> NoteBookHandle := WindowFromProcessID(processinfo.dwProcessID);
> SendMessage(NoteBookHandle,WM_CLOSE,0,0);
> )
> BestRegards,
> DonDan
>
> function WindowFromProcessID(pID: DWORD): HWND;
> Type
> TEnumData = Record
> hW: HWND;
> pID: DWORD;
> End;
> Var
> data: TEnumData;
> function EnumProc( hw: HWND; Var data: TEnumData ): Bool; stdcall;
> var
> pID: DWORD;
> begin
> Result := True;
> GetWindowThreadProcessID( hw, @pID );
> if pID = data.pID then begin
> data.hW := hW;
> Result := False;
> end; { if }
> end; { EnumProc }
>
> begin
> data.pID := pID;
> data.hW := 0;
> EnumWindows( @EnumProc, longint(@data) );
> Result := data.hW;
> End; { WindowFromProcessID }
>
>
>
> "0BIT" <someone@123.com> schrieb im Newsbeitrag
> news:8jzma.73359$ZG5.6410693@amsnews02.chello.com...
> > How do I send messages to other programs ?
> >
> > i've tried this:
> >
> > procedure TForm1.FormCreate(Sender: TObject);
> > var
> > processInfo : TProcessInformation;
> > start : TStartUpInfo;
> > Apprunning : DWord;
> > begin
> > FillChar(Start,Sizeof(Start),#0);
> > start.cb := SizeOf(start);
> > if
> >
CreateProcess(nil,'notepad.exe',nil,nil,true,0,nil,nil,start,processInfo)
> > then begin
> >
> > ******** i think the handle is wrong ?
> > SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
> > ShowMessage('send close message ?');
> > SendMessage(ProcessInfo.hProcess,WM_CLOSE,0,0);
> >
> > repeat
> > Apprunning := WaitForSingleObject
> > (ProcessInfo.hProcess,100);
> > Application.ProcessMessages;
> > until Apprunning <> WAIT_TIMEOUT;
> >
> > ShowMessage('closehandles?');
> > CloseHandle(ProcessInfo.hProcess);
> > CloseHandle(ProcessInfo.hThread);
> > ShowMessage('done');
> > end else
> > ShowMessage('failed');
> > end;
> >
> >
> > Thnks in advance,
> > 0BIT
> >
> >
>
>
Re: Howto send messages to programs
Author: venuslocal
Date: Tue, 15 Apr 2003 13:47
Date: Tue, 15 Apr 2003 13:47
15 lines
1965 bytes
1965 bytes
"0BIT" <someone@123.com> wrote in message news:_nSma.92436$ZG5.7428599@amsnews02.chello.com... > Tnks for your code !! > > The WM_CLOSE message works, now I want to send a string to notepad. IIRC, there's a unit on the delphi cd called SendKeys.pas that will let you do what you want. -- Dru: "Do you love my insides? The parts you can't see?" Spike: "Eyeballs to entrails, my sweet." http://www.planeted.co.uk
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads