interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyControl = class(TObject)
private
{ Private declarations }
FHandle:THandle;
protected
{ Protected declarations }
procedure WndProc(var Msg:TMessage);
public
{ Public declarations }
Constructor Create;
Destructor Destroy;override;
property Handle:THandle read FHandle;
published
{ Published declarations }
end;
implementation
{ TMyControl }
constructor TMyControl.Create;
begin
FHandle:=AllocateHwnd(WndProc);
end;
destructor TMyControl.Destroy;
begin
DeallocateHWnd(FHandle);
inherited;
end;
procedure TMyControl.WndProc(var Msg: TMessage);
begin
try
if Msg.Msg=wm_user+1 then
showmessage('ok')
else msg.Result:= DefWindowProc(FHandle, Msg.msg, msg.wParam, msg.lParam);
except
Application.HandleException(Self);
end;
end;
end.
可以用postmessage(hwnd_broadcast,wm_user+1,0,0)发消息