Связь между процессами при помощи WM_COPYDATA

{codecitation class=»brush: pascal; gutter: false;» width=»600px»}

Оформил: DeeCo

Автор: http://www.swissdelphicenter.ch

// Sender: Send data

// Sender: Daten schicken

procedure TForm1.Button1Click(Sender: TObject);

var

aCopyData: TCopyDataStruct;

hTargetWnd: HWND;

begin

with aCopyData do

begin

dwData := 0;

cbData := StrLen(PChar(Edit1.Text)) 1;

lpData := PChar(Edit1.Text)

end;

// Search window by the window title

// Fenster anhand des Titelzeilentext suchen

hTargetWnd := FindWindowEx(0, 0, nil, PChar(‘WM_COPYDATA-Receiver’));

if hTargetWnd 0 then

SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@aCopyData))

else

ShowMessage(‘No Recipient found!’);

end;

(* ——————————————————————— *)

// Recipient — Receive data

// Empfanger — Daten empfangen

type

TForm1 = class(TForm)

private

{ Private declarations }

procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;

public

{ Public declarations }

end;

procedure TForm1.WMCopyData(var Msg: TWMCopyData);

var

sText: array[0..99] of Char;

begin

// generate text from parameter

// anzuzeigenden Text aus den Parametern generieren

StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);

// write received text

// Empfangenen Text ausgeben

label1.Caption := sText;

end;

{/codecitation}

Добавить комментарий