whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

34 Visitors Online


 
...comunicate process-spanned with WM_COPYDATA?
Autor: Motzi
Homepage: http://www.delphi-area.de
[ Print tip ]  

Tip Rating (15):  
     


// 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
// Empfänger - 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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners