I wrote a D7 application to test the behaviour of Application.OnActivate .
This is the relevant part :
procedure TMainForm.FormCreate (Sender: TObject);
begin
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.FormCreate - Begin');
Application.OnActivate := AppActivate;
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.FormCreate - End');
end;
procedure TMainForm.AppActivate (Sender: TObject);
begin
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppActivate - Begin');
ShowWidthsHeights (Sender);
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppActivate - End');
end;
procedure TMainForm.ShowWidthsHeights (Sender: TObject);
begin
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.ShowWidthsHeights - Begin');
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.ShowWidthsHeights - End');
end;
After starting the application , the content of Memo1 is :
1 - MainForm.FormCreate - Begin
2 - MainForm.FormCreate - End
3 - MainForm.AppActivate - Begin
4 - MainForm.ShowWidthsHeights - Begin
5 - MainForm.ShowWidthsHeights - End
6 - MainForm.AppActivate - End
That is correct .
But if I then click on a shortcut in the taskbar , these 4 lines are added to Memo1 :
7 - MainForm.AppActivate - Begin
8 - MainForm.ShowWidthsHeights - Begin
9 - MainForm.ShowWidthsHeights - End
10 - MainForm.AppActivate - End
Why does D7 do that ?
My application hasn't been activated , on the contrary , it has been deactivated !
To test if the Application.OnDeactivate event is also fired , I added this event handler :
procedure TMainForm.AppDeactivate(Sender: TObject);
begin
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppDeactivate - Begin');
Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppDeactivate - End');
end;
and added this statement to TMainForm.FormCreate :
Application.OnDeactivate := AppDeactivate;
After starting the application , Memo1 contained the same 6 lines as in the original case , but clicking on a shortcut in the taskbar resulted in 8 extra lines in Memo1 :
7 - MainForm.AppDeactivate - Begin
8 - MainForm.AppDeactivate - End
9 - MainForm.AppActivate - Begin
10 - MainForm.ShowWidthsHeights - Begin
11 - MainForm.ShowWidthsHeights - End
12 - MainForm.AppActivate - End
13 - MainForm.AppDeactivate - Begin
14 - MainForm.AppDeactivate - End
So , my application gets deactivated , then activated , and then deactivated again !
That's quite confusing !
WM_ACTIVATEAPP
message that Windows sends to your app. Why Windows does so, I do not know. – BiseOutputDebugString
and the 'Event Log' (ctrl+alt+v) instead of logging to the memo to be sure. – Goliath