Thema: Delphi Windows API design

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#23
  Alt 6. Mai 2003, 11:36
Please don't send me any code. I wont have the time to do your work. Just post the relavent code. But I found some code for WM_COPYDATA. But again you will have to modify your c-programs:

First program, the sender:
Delphi-Quellcode:
function FindWindowByTitle(WindowTitle : string) : Hwnd;
var
  NextHandle : Hwnd;
  NextTitle : array[0..260] of char;
begin
  NextHandle := GetWindow(Application.Handle,GW_HWNDFIRST);
  while (NextHandle > 0) do
  begin
    GetWindowText(NextHandle,NextTitle,255);
    if (pos(WindowTitle,StrPas(NextTitle)) <> 0) then
    begin
      result := NextHandle;
      exit;
    end
    else
      NextHandle := GetWindow(NextHandle,GW_HWNDNEXT);
    end;
    result := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  struct: CopyDataStruct;
begin
  struct.cbData := Length(Edit1.Text);
  struct.lpData := PChar(Edit1.Text + #0);
  SendMessage(FindWindowByTitle('Form2'), WM_COPYDATA, handle, Integer(@struct));
end;
Second program, the receiver:
Delphi-Quellcode:
type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure GetData(var msg: TMessage); message WM_COPYDATA;
...
procedure TForm1.GetData(var msg: TMessage);
var
  struct: PCopyDataStruct;
begin
  struct := Ptr(msg.LParam);
  Form1.Label1.Caption := PChar(struct^.lpData);
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat