Author: Jonas Bilinkevicius
I have an application that auto-minimizes itself after 4 seconds, when maximized
(using TTimer). The main form has a menu. I want the Timer to be disabled while the
user browses the menu items. Is that possible?
Answer:
Solve 1:
Add this line to your form declaration:
1 2 protected3 4 procedure WMMenuSelect(var msg: TWMMenuSelect); message WM_MenuSelect;
5 6 andthen add this procedure:
7 8 procedure TForm1.WMMenuSelect(var msg: TWMMenuSelect);
9 begin10 tmrAutoClose.Enabled := (msg.MenuFlag = $FFFF);
11 end;
Solve 2:
12 13 Yes. The form will get one special message when the menu is first opened
14 (WM_ENTERMENULOOP) and a second when the menu isfinally closed (WM_EXITMENULOOP).
15 Add handlers for these and disable/ enable the timer in them.
16 17 { ... }18 private19 20 procedure WMEnterMenuLoop(var msg: TMessage);
21 message WM_ENTERMENULOOP;
22 procedure WMExitMenuLoop(var msg: TMessage);
23 message WM_EXITMENULOOP;
24 { ... }25 26 procedure TForm1.WMEnterMenuLoop(var msg: TMessage);
27 begin28 IdleTimer.Enabled := false;
29 inherited;
30 end;
31 32 procedure TForm1.WMExitMenuLoop(var msg: TMessage);
33 begin34 IdleTimer.Enabled := true;
35 inherited;
36 end;