1. Technology

Hide a Delphi 2007 Application Button from the TaskBar (with MainFormOnTaskBar)

By

In all Delphi versions up to Delphi 2007, the button on the Windows TaskBar, for a Delphi application, belongs to the Application window, the hidden window maintained by the Application object, not the main form window.

With Delphi 2007, a new property of the Application object, the MainFormOnTaskbar property controls how Windows taskbar buttons are handled by VCL.

If MainFormOnTaskbar is true, a taskbar button represents the application's main form and displays its caption. If false, a taskbar button represents the application's (hidden) main window and bears the application's Title.

By design, the MainFormOnTaskbar property is set to true for any new Delphi 2007 application. You can change this value by editing the projects (DPR) source code. MainFormOnTaskBar should be set after Application.Initialize and before main form creation.

Hide the Taskbar button for Delphi <= 2006

With Delphi versions up to Delphi 2007 a simple tweak to the application's window style using the SetWindowLong API call allowed you to hide the taskbar button (Delphi <= 2006).

This code no longer works with Delphi 2007!

Hide the Taskbar button for Delphi 2007

With Delphi 2007, to hide the taskbar button you'll need a few code lines:
  • Set MainFormOnTaskBar to FALSE
  • Call
    ShowWindow(Application.Handle, SW_HIDE);
    inside the main form's OnShow event handler.
  • Call
    ShowWindow(Application.Handle, SW_HIDE);
    inside the main form's OnActivate event handler.

"Why would I want to hide the taskbar button?"

Think of Windows System Tray applications - a perfect place form programs that are left running for long periods of time with no (or ocassional) user interaction.

Delphi tips navigator:
» Set TRichEdit Print Margins Programmatically
« Calculating the Zodiac Sign from the Birth Date

©2014 About.com. All rights reserved.