Author: Jonas Bilinkevicius
How to detect if a menu as a whole is currently open or selected
Answer:
1 { ... }2 type3 TForm1 = class(TForm)
4 MainMenu1: TMainMenu;
5 item01: TMenuItem;
6 item11: TMenuItem;
7 item21: TMenuItem;
8 private9 { Private declarations }10 public11 procedure WMMENUSELECT(var M: TWMMENUSELECT); message WM_MENUSELECT;
12 end;
13 {...}14 15 procedure TForm1.WMMENUSELECT(var M: TWMMENUSELECT);
16 begin17 inherited;
18 19 {This beeps even if it is the sysmenu (control menu) and/or on any selected item: 20 }21 { messagebeep(MB_ICONASTERISK); }22 23 { This beeps when MainMenu1 is opened, but only beeps on item[0]: }24 if M.menu = Mainmenu1.handle then25 messagebeep(MB_ICONASTERISK);
26 end;
27 28 end.