Detect if user select menu item

Posted in Components

Use should hook WM_MENUSELECT message for this. In this example, when user select some menu item, form color will change.

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMMenuSelect(var Msg: TWMMenuSelect);
      message WM_MENUSELECT;
  public
    { Public declarations }
  end;

...

procedure TForm1.WMMenuSelect(var Msg: TWMMenuSelect);
begin
  inherited;
  Randomize;
  Color:=RGB(Random(255), Random(255), Random(255));
end;