Taskbar/Task Manager/Vista issues in applications built with Delphi 2007
There has been a bit of discussion in the CodeGear newsgroups recently regarding some issues to do with applications built with Delphi 2007, and how it affects appearance on the Windows taskbar, the task manager list, and Vista.
Some solutions suggest making some modifications to Forms.pas, however this doesn't help those like me who build a number of applications using runtime packages.
As soon as I was aware of the issues, I set about finding the solutions, and like some people, found the newsgroups a valuable resource. I also needed to do a little experimenting in order to make things behave as they should, and the following is the result.
When creating a new application in Delphi 2007, the following appears in the project source:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Note the new MainFormOnTaskbar property of the Application object. This means that what you see on the taskbar is the icon and caption of the main form (when it appears). So how about if you have a splash screen, like I often use, and if the splash screen is created and shown before the main form is even created? eg:
Application.Initialize;
Application.MainFormOnTaskbar := True;
frmSplash := TfrmSplash.Create(nil);
frmSplash.Show;
frmSplash.Update;
Application.CreateForm(TfrmMain, frmMain);
frmSplash.Free;
Application.Run;
Without further modification, when the application runs and the splash screen is showing, there is no window on the taskbar. To solve this, I override the CreateParams method of TfrmSplash:
procedure TfrmSplash.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle and not WS_EX_TOOLWINDOW or WS_EX_APPWINDOW;
end;
This causes the a window to appear in the taskbar. That solves one issue, however it raises another: there's no caption in my splash screen, and therefore no caption in the window on the taskbar, so I set the application title in the project options, and override the Create method in TfrmSplash:
constructor TfrmSplash.Create(AOwner: TComponent);
begin
inherited;
// Fix the taskbar/splash issue
Caption := Application.Title;
end;
Note that changing the application title in the project options will insert the line just before Application.CreateForm, so I move it to just before the call to Application.MainFormOnTaskbar := True so that the splash screen has the right value for the title.
Now we have a window appearing in the taskbar, and it has a caption, however there is one more issue: under operating systems prior to Vista, the application doesn't appear in the task manager applications list. The solution is to make the following call:
if (Win32MajorVersion < 6) then
SetWindowText(Application.Handle, PChar(Application.Title));
I could add the call to , however if I chose to remove the splash screen and just use the main form, I'd end up with the same problem. Since I'll always be using the main form, I add it to TfrmMain.Create:
constructor TfrmMain.Create(AOwner: TComponent);
begin
inherited;
Caption := Application.Title;
// Fix the task list issue for non-Vista
if (Win32MajorVersion < 6) then
SetWindowText(Application.Handle, PChar(Application.Title));
// Simulate the app doing something while the splash screen is showing
Sleep(6000);
end;
There was another issue under discussion, which is the appearance of the application in the taskbar thumbnail and Flip3D. Unfortunately, I don't have an Aero-capable PC with Vista installed at the moment.
Full source for the example application is available here.

Comments
-
Please login first in order for you to submit comments