Registriert seit: 16. Jun 2004
172 Beiträge
Delphi 2005 Professional
|
Re: Sendmessage pointer of array
30. Nov 2005, 14:04
Hi,
ja funktioniert gut - ich finde das ist eine schöne möglichkeit variablen zwischen meinen
Programmen auszutauschen
einfach eine form mit einem label + button code hineinkopieren und 2x das Prog starten..
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
{ Basiert auf CodeSnippet [url]http://www.swissdelphicenter.ch/de/showcode.php?id=418[/url] }
type
TWMMYMessage = record
Msg: Cardinal; // ( first is the message ID )
Handle: HWND; // ( this is the wParam, Handle of sender)
Info: Longint; // ( this is lParam, pointer to our data)
Result: Longint;
end;
Mymessage = record
msgtext: String[20];
msgint : integer;
end;
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
procedure DefaultHandler( var Message); override;
procedure WMMYMessage( var Msg: TWMMYMessage);
end;
var
Form1: TForm1;
WM_OURMESSAGE: DWORD;
mymsg: mymessage;
strtest : string[30];
implementation
{$R *.dfm}
procedure TForm1.DefaultHandler( var Message);
var
ee: TWMMYMessage;
begin
with TMessage( Message) do
begin
if (Msg = WM_OURMESSAGE) then
begin
ee.Msg := Msg;
ee.Handle := wParam;
ee.Info := lParam;
// Checking if this message is not from us
if ee.Handle <> Handle then
WMMYMessage(ee);
end
else
inherited DefaultHandler( Message);
end;
end;
procedure TForm1.WMMYMessage( var Msg: TWMMYMessage);
var
text: string;
begin
text:=string(pchar(pointer(Msg.Info)));
delete(text,1,1);
Label1.Caption := text;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(HWND_BROADCAST, WM_OURMESSAGE, Handle, integer(@strtest));
//SendMessage(HWND_BROADCAST, WM_OURMESSAGE, Handle, integer(@mymsg));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
mymsg.msgtext:=' test';
mymsg.msgint:=1234;
strtest:=' strtest';
end;
initialization
WM_OURMESSAGE := RegisterWindowMessage(' broadcast message');
end.
|
|
Zitat
|