Envoyer un message Windows avec SendMessage

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Ear( var Message: TMessage); message WM_User + 4242;
//Important - Handler that receive the Message

private
{ Private-Deklarationen }

public
{ Public-Deklarationen }

end;

var
Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
txt: string;

begin
txt := 'Hello World';
SendMessage(form1.Handle, WM_User + 4242, 0, DWORD(PChar(txt)));
end;

//To receive this Message that is addressed to form1.handle you need a messagehandler at form1

procedure TForm1.Ear( var Message: TMessage);
var
txt: PCHar;

begin
txt := PCHar(Message.LParam);
ShowMessage(txt);
Message.Result := 1;
end;
end.
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour19/11/2001
VisualisationVu 979 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Systeme
Auteur de l'article
Communauté Delphi Communauté Delphi
connecté le 02/11/2011
0 articles dans la section
Contacter l'auteur