Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
461 Beiträge
Delphi XE4 Professional
|
Re: Interaktion zweier Programme
25. Mär 2009, 16:53
.. ich hätte hier ein paar Zeilen, die den "Sendmessage"-Teil betreffen...
HTH
Erich
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
Memo1: TMemo;
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
procedure WMCopyData( var Msg: TWMCopyData); message WM_COPYDATA;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// How to send Data to my Software
procedure TForm1.SpeedButton1Click;
var
aCopyData: TCopyDataStruct;
p: PChar;
begin
p := ' Hello World'; // die zu übertragenden Daten
with aCopyData do begin
dwData := 4; // kann als Senderidentifikation verwendet werden
cbData := StrLen(p) + 1; // Sendespeicherlänge terminieren..
lpData := p;
end;
SendMessage(FindWindow(' TForm1', nil), WM_COPYDATA, Longint( Handle),Longint(@aCopyData));
// http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx = FindWindow
// http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx = Sendmessage
// http://msdn.microsoft.com/en-us/library/ms649011(VS.85).aspx = WM_COPYDATA
// http://msdn.microsoft.com/en-us/library/ms649010(VS.85).aspx = TCopyDataStruct
end;
procedure TForm1.WMCopyData( var Msg: TWMCopyData);
var x :integer;
s :PChar;
begin
StrLCopy(s, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);
x := (Integer(Msg.CopyDataStruct.dwData));
memo1.Lines.Append (' Nachricht:'+s+' von SenderID:'+ inttostr(x));
end;
end.
Erich Wanker - for life:=1971 to lebensende do begin ..
|
|
Zitat
|