Partager des données entre deux applications

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;

type
PCopyDataStruct = ^TCopyDataStruct;
TCopyDataStruct = record
dwData: LongInt;
cbData: LongInt;
lpData: Pointer;
end;

type
PEnvoiFax = ^TEnvoiFax;
TEnvoiFax = packed record
Destinataire: string[255];
TypeDocument: integer;
DateEnvoi: TDateTime;
EnvoiFait: boolean;
testdata: string[255];
end;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
RadioGroup1: TRadioGroup;
DateTimePicker1: TDateTimePicker;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
procedure WMCOPYDATA( var Msg : TMessage ); message wm_copydata;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
h: THandle;
CopyDataStruct: TCopyDataStruct;
Envoi: TEnvoiFax;
begin
{Envoyer une structure de données avec WM_COPYDATA}
h := FindWindow(nil, pchar(edit2.Text));
if h = 0 then
ShowMessage('Le receveur est inact if ')
else
begin
with Envoi do
begin
Destinataire := Edit1.text;
TypeDocument := RadioGroup1.ItemIndex;
DateEnvoi := DateTimePicker1.DateTime;
EnvoiFait := CheckBox1.Checked;
testdata := memo1.Text;
end;

with CopyDataStruct do
begin
dwData := 1;
cbData := sizeof(Envoi);
lpData := @Envoi;
end;
SendMessage( h, WM_COPYDATA, Form1.Handle, LongInt(@CopyDataStruct));
end;

end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
Caption := edit1.Text;
end;

procedure TForm1.WMCOPYDATA( var Msg: TMessage);
begin
with PEnvoiFax(PCopyDataStruct(Msg.LParam)^.lpData)^ do
begin
Edit1.text := Destinataire;
RadioGroup1.ItemIndex := TypeDocument;
DateTimePicker1.DateTime := DateEnvoi;
CheckBox1.Checked := EnvoiFait;
memo2.Text := testdata;
end;
end;

end.
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour25/12/2004
VisualisationVu 1255 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Autre categorie
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur