Link to home
Start Free TrialLog in
Avatar of karouri
karouri

asked on

Control handles user-defined message?

I made a component inherited from TControl and I need to make this component catches a user defined message (WM_USER+1) that is currently being caught by the form. Is this possible and how?
Avatar of hubdog
hubdog

unit MyControl;

interface

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

type
  TMyControl = class(TControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
    procedure WMOwndefine(var Msg:TMessage);message wm_user+1;
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Sample', [TMyControl]);
end;

{ TMyControl }

procedure TMyControl.WMOwndefine(var Msg: TMessage);
begin
  //do what you want
end;

end.
Avatar of karouri

ASKER

That is exactly what I am doing, however it didn't 'do what I want'.
When I define the same definition as above for the form   (i.e. TForm1.WMOwndef(var msg:TMessage);message WM_USER+2;)  I am able to respond from within TForm1.WMOwndef, but the component isn't able to do it ..
ASKER CERTIFIED SOLUTION
Avatar of hubdog
hubdog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or you can use
postmessage(hwnd_broadcast,wm_user+1,0,0);
to sendmessage .