2005. október 8., szombat

How to detect if a menu as a whole is currently open or selected


Problem/Question/Abstract:

How to detect if a menu as a whole is currently open or selected

Answer:

{ ... }
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    item01: TMenuItem;
    item11: TMenuItem;
    item21: TMenuItem;
  private
    { Private declarations }
  public
    procedure WMMENUSELECT(var M: TWMMENUSELECT); message WM_MENUSELECT;
  end;
  {...}

procedure TForm1.WMMENUSELECT(var M: TWMMENUSELECT);
begin
  inherited;

  {This beeps even if it is the sysmenu (control menu) and/or on any selected item: }
  { messagebeep(MB_ICONASTERISK);  }

  { This beeps when MainMenu1 is opened, but only beeps on item[0]: }
  if M.menu = Mainmenu1.handle then
    messagebeep(MB_ICONASTERISK);
end;

end.

Nincsenek megjegyzések:

Megjegyzés küldése