I wrote this simple program
Clicking Button1 should send a message to the WndProc procedure. But nothing happens. What's wrong?
I think you almost had it. RegisterWindowMessage is strictly a Win API function and offhand I suspect that its return value doesn't mean much to Lazarus.
I recreated your example using WM_USER + 1 as the message value and it works fine with Delphi, Lazarus on Windows and Lazarus on OS X (Carbon widgetset). If you're starting with Delphi, you can convert your apps to Lazarus and retain Delphi compatibility using XDev Toolkit:
http://wiki.lazarus.freepascal.org/XDev_Toolkitunit Unit1;
interface
uses
{$IFNDEF LCL} Windows, Messages, {$ELSE} LclIntf, LMessages, LclType, LResources, {$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
{$IFDEF LCL}
type
TMessage = TLMessage;
{$ENDIF}
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
WM_MY_MESSAGE: UINT;
public
{ public declarations }
procedure WndProc(var Msg: TMessage); override;
end;
var
Form1: TForm1;
implementation
{$IFNDEF LCL}
{$R *.dfm}
{$ENDIF}
procedure TForm1.Button1Click(Sender: TObject);
begin
// PostMessage(HWND_BROADCAST, WM_MY_MESSAGE, 0, 0)
PostMessage(Self.Handle, WM_MY_MESSAGE, 0, 0)
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// WM_MY_MESSAGE:= RegisterWindowMessage('LazarusProva');
WM_MY_MESSAGE := WM_USER + 1;
end;
procedure TForm1.WndProc(var Msg: TMessage);
begin
if Msg.msg= WM_MY_MESSAGE then begin
Memo1.Lines.Append('Ok');
end else inherited WndProc(Msg);
end;
initialization
{$IFDEF LCL}
{$I unit1.lrs} {Include form's resource file}
{$ENDIF}
end.