Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MainFormOnTaskbar and OnRestore

231 views
Skip to first unread message

Pieter Zijlstra

unread,
Aug 6, 2008, 7:54:20 PM8/6/08
to
Part 1 (OnRestore events):
==========================
Application.OnRestore and/or TApplicationEvents.OnRestore does not work
when you have MainFormOnTaskbar set to True (the default for new
projects).

This is on D2007 11.0.2902.10471 on XP SP3 (also checked on a old
Windows ME box).

This should be easy to verify by creating a new project, drop a
TApplicationEvents on it and add two handlers for OnMinimize and
OnRestore:

procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
Caption := 'Minimized';
end;

procedure TForm1.ApplicationEvents1Restore(Sender: TObject);
begin
Caption := 'Restored';
end;

When you minimize the application the Caption of the form will change
to 'Minimized', when you restore the application the OnRestore event is
not called and the Caption stays unchanged.

Part2 (Restoring other forms):
==============================
MainFormOnTaskbar set to True is needed to make use of some of the
Vista features but sometimes one wants a secondary form to behave as a
separate form which does not always stays on top of the "mainform" (and
optional have a separate button on the Taskbar). This can be done by
using the following code in the second form:

type
TForm2 = class(TForm)
protected
procedure CreateParams(var params: TCreateParams); override;
end;

procedure TForm2.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
// params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
params.WndParent := Application.Handle;
end;

Note: the commented line can be enabled to get a second button on the
Taskbar.

When minimizing an application with such a secondary form open and then
restoring it, will restore the first (main)form but the secondary form
is just "gone". The secondary form is still there somewhere but you
have now way of showing it.


What happens is that when you minimize the application a helper
variable is set to indicate that the application is minimized
(AppIconic in Forms.pas). This variable is used to determine when the
application is being restored if it should restore any other forms and
call the OnRestore event (see TApplicationHelper.InternalRestore and
Forms.IsIconic).

The problem is that this helper variable is reset when the application
receives a WM_ACTIVATEAPP message before it reaches the InternalRestore
routine and therefore the other forms are not restored (and the
OnRestore event is never called).

<application start>
01:42:06.765 WM_ACTIVATEAPP Active: 1 ThreadID:4980

<minimizing app>
01:42:08.906 TApplication.Minimize
01:42:08.921 WM_ACTIVATEAPP Active: 0 ThreadID:4980

<restoring app>
01:42:10.796 WM_ACTIVATEAPP Active: 1 ThreadID:4980
01:42:10.812 TApplication.InternalRestore


And now the question: Can I QC it like this?

--
Pieter

Pieter Zijlstra

unread,
Aug 6, 2008, 8:53:25 PM8/6/08
to
Pieter Zijlstra wrote:

> 01:42:10.812 TApplication.InternalRestore
>
> And now the question: Can I QC it like this?

Maybe I should point out that inside TApplication.InternalRestore the
line with...

<code>
if IsIconic(FHandle) then
</code>

...returns False?

--
Pieter

Peter Below (TeamB)

unread,
Aug 7, 2008, 6:12:17 AM8/7/08
to
Pieter Zijlstra wrote:

> Part 1 (OnRestore events):
> ==========================
> Application.OnRestore and/or TApplicationEvents.OnRestore does not
> work when you have MainFormOnTaskbar set to True (the default for new
> projects).

While certainly true this is to be expected. With MainformOnTaskbar set
to true you are not minimizing the application, you are minimizing the
main form. IMO this is more a documentation issue.

Your second problem is something that should be adressed. Your report
is detailed enough for QC, but please provide a sample application that
shows the problem with the report.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

0 new messages