The new VCL property TApplication.MainFormOnTaskbar in Delphi 2007

In Delphi 2007, one of the changes we made in VCL was to provide better support for Window Vista, particularly in relation to window animations which occur when your application is minimized, restored or closed. Nathanial Woolls has a good write-up on some of the related issues.

Ok, I’d like to back up a little bit and explain why Delphi works this way in the first place. When Delphi first came out it used multiple free floating windows that all worked in concert with one another where the “main” window contained the menus and toolbars. When you minimized the main window the rest of the IDE’s windows disappeared and likewise when you restored they all came back. Well, that functionality doesn’t exactly come for free. There is a fair amount of code to try and make multi-window VCL applications behave like single window applications with regard to min/max/restore operations. Of course, this was well before Windows 95 and the taskbar which introduces additional complications.

The primary issue at hand is that the TApplication object has a hidden window used to deal with a lot of these operations although it wasn’t perfect either. In Delphi 2007, there is a new TApplication property called MainFormOnTaskbar that’s documented in the readme.txt (as it came in too late for formal documentation). The readme states:

“Delphi 2007 adds a new
property to TApplication called MainFormOnTaskBar. It
defaults to True for new Delphi 2007 applications and False for existing ones. The
property controls several aspects of how VCL applications perform with regard
to minimize/maximize/restore operations in Windows. Be aware that it will
affect the Z-order of your MainForm, in the event your applications depend on
the old behavior. MainFormOnTaskBar is intended to be set at startup and
persist throughout the duration of the application, changing this property at
runtime could result in unexpected behavior. The major reason for this change
was to better support several new features available on Windows Vista’s
Aero Theme. To update existing VCL applications, add the following line to the
project’s .dpr after “Application.Initialize;”:

Application.MainFormOnTaskbar := True;

Basically, what this property does is change the use of the TApplication hidden window and favor’s the MainForm’s window handle. This introduced a number of subtle changes like those mentioned above. Unfortunately, even prior to RTM we identified a few more issues and we’re actively investigating those now. I’ve seen a few posts on the public newsgroups like this and this which we are very much aware of. In the case of BDS 2006 minimizing the IDE should restore its taskbar button since Delphi 2007 replaces the VCL100.bpl package used by BDS 2006.

What you need to know
We’re working on identifying and fixing issues related to this property. In fact, Seppy has a spreadsheet that identifying 32 (at last count) scenarios and combinations thereof including things like MainFormOnTaskBar, ShowMainForm, programmatically setting Form.Visible, changing Visible in OnShow/OnCreate, changing Visible with a timer and Taskbar icons which we’ll continue to augment as we go. So, this isn’t the end of the MainFormOnTaskbar story.

Lastly, while this is a new property for Delphi 2007 it was added in a non-interface breaking manner just so we’re clear.

In case you missed, I’m currently on vacation and will follow-up next week.

4 thoughts on “The new VCL property TApplication.MainFormOnTaskbar in Delphi 2007

  1. So for clarification, a project that has been developed in BDS2006 and is converted over to D2007 (i.e. opened in D2007) should have the line "Application.MainFormOnTaskbar := True;" added – correct? I would have preferred this to be set as default but that’s a minor issue.
    What about the other changes e.g. TWinControl are now double buffered – is this taken care of automatically or do I need to still set DoubleBuffered := true for control in projects converting over from BDS 2006?
    Furthermore, what about adding "WS_EX_COMPOSITED" to a forms Params.ExStyle – do I need to add this to converted projects or is it now automatic for all D2007 projects?
    Have a great vacation – I’m in no hurry for the answer, it can wait until you get back,
    Regards,
    Steve Maughan
    BTW I often don’t get a comment "Code" when I try to add a comment and have to refresh / save comment several times before it appears. I’m using Firefox 2.0

  2. Steve,

    So for clarification, a project that has been developed in BDS2006 and is converted over to D2007 (i.e. opened in D2007) should have the line "Application.MainFormOnTaskbar := True;" added – correct?

    Yes, that’s correct.

    What about the other changes e.g. TWinControl are now double buffered

    TWinControl has not changed WRT the DoubleBuffered property. It’s a tool you’ll need to use accordingly in your own VCL applications, it’s not a one-stop-fix.

    Furthermore, what about adding "WS_EX_COMPOSITED" to a forms Params.ExStyle

    VCL does not surface support for this style so you’ll need to add it programmatically as I indicated in a prior post. You should refer to the MSDN for more information on that style especially if it makes sense moving to Vista.

    BTW I often don’t get a comment "Code" when I try to add a comment and have to refresh / save comment several times before it appears. I’m using Firefox 2.0

    I see the same problem with FF on several different blogs. I’ve noticed I never have a problem with CAPTCHA images using IE7 and I don’t know why.

  3. Hi
    I noticed the Visible property must be false on my main form, otherwise the taskbar button is not displayed.
    Regards,
    Hein Gustavsen

  4. Good tip Hein Gustavsen,
    I had the same problem after importing D7 forms, searching hours for a solution.
    You solved it , thanks mate
    Ton

Comments are closed.