Title: How do I add a form to the taskbar?
Question: Windows automatically adds a single taskbar button for your application, but you can force a seperate button for specific windows.
Answer:
To add a taskbar button for a specific application window, you need to override the CreateParams method of TForm and add WS_EX_APPWINDOW to the window's extended style:
type
TMyForm = class(TForm)
protected
procedure CreateParams(var Params: TCreateParams);
end;
implementation
procedure TMyForm.CreateParams(var Params: TCreateParams);
begin
ExStyle := ExStyle or WS_EX_APPWINDOW;
end;
This will add the taskbar button for your form, but there are a few other minor details to handle. Most obviously, your form still receives minimize/maximize that get sent to the parent form (the main form of the application). In order to avoid this, you can install a message handler for WM_SYSCOMMAND by adding a line such as:
procedure WMSysCommand(var Msg: TMessage); WM_SYSCOMMAND;
procedure TParentForm.WMSysCommand(var Msg: TMessage);
begin
if Msg.wParam = SC_MINIMIZE then
begin
// Send child windows message, don't
// send to windows with a taskbar button.
end;
end;
Note that this handler goes in the PARENT form of the one you want to behave independantly of the rest of the application, so as to avoid passing on the minimize message. You can add similar code for SC_MAXIMIZE, SC_RESTORE, etc.