Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  166

•  TDictionary Custom Sort  3 340

•  Fast Watermark Sources  3 093

•  3D Designer  4 849

•  Sik Screen Capture  3 348

•  Patch Maker  3 554

•  Айболит (remote control)  3 664

•  ListBox Drag & Drop  3 016

•  Доска для игры Реверси  81 715

•  Графические эффекты  3 946

•  Рисование по маске  3 250

•  Перетаскивание изображений  2 631

•  Canvas Drawing  2 754

•  Рисование Луны  2 584

•  Поворот изображения  2 191

•  Рисование стержней  2 169

•  Paint on Shape  1 569

•  Генератор кроссвордов  2 239

•  Головоломка Paletto  1 767

•  Теорема Монжа об окружностях  2 232

•  Пазл Numbrix  1 685

•  Заборы и коммивояжеры  2 057

•  Игра HIP  1 282

•  Игра Go (Го)  1 230

•  Симулятор лифта  1 475

•  Программа укладки плитки  1 218

•  Генератор лабиринта  1 548

•  Проверка числового ввода  1 366

•  HEX View  1 497

•  Физический маятник  1 358

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Передать строки, картинки (streams) между процессами




{ 
  The WM_COPYDATA messages makes it possible to transfer information 
  between processes. It does this by passing the data through the kernel. 
  Space is allocated in the receiving process to hold the information that is copied, 
  by the kernel, from the source process to the target process. 
  The sender passes a pointer to a COPYDATASTRUCT, which is defined as a structure 
  of the following: 
} 

type 
  TCopyDataStruct = packed record 
    dwData: DWORD;   // anwendungsspezifischer Wert 
    cbData: DWORD;   // Byte-Lдnge der zu ьbertragenden Daten 
    lpData: Pointer; // Adresse der Daten 
  end; 
 

{ Sender Application } 

unit SenderApp; 

interface 

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

type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Edit1: TEdit; 
    Button2: TButton; 
    Image1: TImage; 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    procedure SendCopyData(hTargetWnd: HWND; ACopyDataStruct:TCopyDataStruct); 
  public 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

// Sender: Send data 
procedure TForm1.SendCopyData(hTargetWnd: HWND; ACopyDataStruct:TCopyDataStruct); 
begin 
  if hTargetWnd <> 0 then 
    SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@ACopyDataStruct)) 
  else 
    ShowMessage('No Recipient found!'); 
end; 

// Send Text from Edit1 to other app 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  MyCopyDataStruct: TCopyDataStruct; 
  hTargetWnd: HWND; 
begin 
  // Set up a COPYDATASTRUCT structure for use with WM_COPYDATA 
  // TCopyDataStruct mit den Sende-Daten Infos ausfьllen 
  with MyCopyDataStruct do 
  begin 
    dwData := 0; // may use a value do identify content of message 
    cbData := StrLen(PChar(Edit1.Text)) + 1;  //Need to transfer terminating #0 as well 
    lpData := PChar(Edit1.Text) 
  end; 
  // Find the destination window for the WM_COPYDATA message 
  // Empfдnger Fenster anhand des Titelzeilentextes suchen 
  hTargetWnd := FindWindow(nil,PChar('Message Receiver')); 
  // send the structure to the receiver 
  // Die Struktur an den Empfдnger schicken 
  SendCopyData(hTargetWnd, MyCopyDataStruct); 
end; 

// Send Image1 to other app 
procedure TForm1.Button2Click(Sender: TObject); 
var 
  ms: TMemoryStream; 
  MyCopyDataStruct: TCopyDataStruct; 
  hTargetWnd: HWND; 
begin 
  ms := TMemoryStream.Create; 
  try 
    image1.Picture.Bitmap.SaveToStream(ms); 
    with MyCopyDataStruct do 
    begin 
      dwData := 1; 
      cbData := ms.Size; 
      lpData := ms.Memory; 
    end; 
    // Search window by the window title 
    // Empfдnger Fenster anhand des Titelzeilentextes suchen 
    hTargetWnd := FindWindow(nil,PChar('Message Receiver')); 
    // Send the Data 
    // Daten Senden 
    SendCopyData(hTargetWnd,MyCopyDataStruct); 
  finally 
    ms.Free; 
  end; 
end; 

end. 

{*********************************************************************} 

{ Receiver Application } 

unit ReceiverApp; 

interface 

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

type 
  TForm1 = class(TForm) 
    Image1: TImage; 
    Label1: TLabel; 
  private 
    procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; 
    { Private-Deklarationen } 
  public 
    { Public-Deklarationen } 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure TForm1.WMCopyData(var Msg: TWMCopyData); 
var 
  sText: array[0..99] of Char; 
  ms: TMemoryStream; 
begin 
  case Msg.CopyDataStruct.dwData of 
    0: { Receive Text, Text empfangen} 
      begin 
        StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData); 
        label1.Caption := sText; 
      end; 
    1: { Receive Image, Bild empfangen} 
      begin 
        ms := TMemoryStream.Create; 
        try 
          with Msg.CopyDataStruct^ do 
           ms.Write(lpdata^, cbdata); 
           ms.Position := 0; 
          image1.Picture.Bitmap.LoadFromStream(ms); 
        finally 
          ms.Free; 
        end; 
      end; 
  end; 
end; 
end.





Похожие по теме исходники

Files Threads Streams

Сообщения между процессами Windows




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте