Why Don’t Applications Written in Delphi “Fly” to the Taskbar?

Applications created in Delphi 1 to 4 (not 5 and up) don’t “fly” to the taskbar but hide like in Windows 3.1x. This is because Borland’s programmers turned this function off. Why?! Well, this is because the main window of the program is not the one we create in the IDE. The program’s main window is TApplication, so if the animation were turned on the application would “fly” but it would be kinda weird because it wouldn’t be our main window that would “fly”:) Well, there are a few ways to get over this:

1) You can turn on the window animation in the unit Form. Before doing this though you may want to back up this unit ;-)
Here’s the code:

  ...
  procedure ShowWinNoAnimate(Handle: HWnd; CmdShow: Integer);
  var
    Animation: Boolean;
  begin
    Animation := GetAnimation;
    if Animation then
      SetAnimation(False);
    ShowWindow(Handle, CmdShow);
    if Animation then
      SetAnimation(True);
  end;
  ...

Because this procedure is called from other functions it should be changed to:

  ...
  procedure ShowWinNoAnimate(Handle: HWnd; CmdShow: Integer);
  begin
    ShowWindow(Handle, CmdShow);
  end;
  ...

2) I would consider this is the best way. Add this code to your project’s source unit:

  ...
  uses
    Windows;
  ...
  var
    iExStyle: Integer;
  ...
    Application.Initialize;
    iExStyle := GetWindowLong(Application.Handle, GWL_EXSTYLE);

Add this code to your main window’s unit:

  ...
  public
    procedure CreateParams(var Params: TCreateParams); override;
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
  ...
  procedure TMainForm.CreateParams(var Params: TCreateParams);
  begin
    inherited CreateParams(Params);
    with Params do
      ExStyle := ExStyle or WS_EX_APPWINDOW;
  end;

  (* This will take care of the Minimize command so that the proper window
   * will "fly" to the taskbar.
   *)
  procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
  begin
   if Message.CmdType and $FFF0 = SC_MINIMIZE then
     WindowState := wsMinimized
   else
     inherited;
  end;

3) This is the worst you can do :-) Use a Delphi component to do the job.

Tags: , , , , , , , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login