System Delphi

Title: Zooming windows
Question: Unfortunately Inprise (actually it was Borland) left away the zooming-effect that Windows95 uses to minimize and restore forms. Using the code described in this project, you can build it into your apps.
Answer:
Basics: How Delphi uses forms
Maybe you have already discovered that your apps' taskbar buttons don't have the same caption as the main form of your apps (e.g. if you set an app name in the application options that differs from your main form's caption). This is because Delphi uses the application as the real main form - it is hidden from the user, but it is there (you can make it visble with some tricks). The buttons of your application's windows are not shown in the taskbar. Now the second thing about zooming-windows is that Borland wrote its own methods to minimize and restore forms, instead of using the ones that windows offers. In a way this is logical: if forms aren't shown in the taskbar, why should they zoom into it? However, this is something the users of your app don't know and they will wonder why your windows do not zoom.
Turn your form into an APPWINDOW
In order to make your forms zoom, you first have to put them into the taskbar. Windows95 provides an extra window-style that determines whether a window is shown in the taskbar or not. What you have to do is simply to set this style. I already wrote a project about using window-styles that Delphi does not support (sorry, but it's not available in english - here's the german one).
Put the following line of code into the form declaration:
procedure CreateParams(var Params: TCreateParams); override;
And this procedure into the implementation:
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle:= Params.ExStyle or WS_EX_APPWINDOW;
end;
Running your application, you will see that Form1 is now in the taskbar.
Get the application off the taskbar
Of course you don't want two buttons on the taskbar for only one form. So you will have to hide the application window (which is already invisible to the user). You can do this in your form's OnCreate-method:
procedure TForm1.FormCreate(Sender: TObject); begin
ShowWindow(Application.Handle, SW_HIDE);
end;
Now make it zoom
Now you have to implement the zooming-effect. In order to do so, you have to handle the WM_SYSCOMMAND message that Windows sends to a form when it should minimize or restore itself. In the message handler, you will have to use the standard Windows API calls used to minimize forms instead of using the ones that Delphi provides. First, put the following line into the private part of your forms declaration:
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
Then, write the following message handler:
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
case Msg.CmdType of
SC_MINIMIZE: begin
ShowWindow(Handle, SW_MINIMIZE);
(**) Application.Minimize;
(**) ShowWindow(Application.Handle, SW_HIDE);
(**) ShowWindow(Handle, SW_MINIMIZE);
end;
SC_RESTORE: begin
(**) Application.Restore;
ShowWindow(Handle, SW_RESTORE);
(**) ShowWindow(Application.Handle, SW_HIDE);
end;
else
inherited;
end;
end;
What does this method do? First, it minimizes itself by calling the ShowWindow-procedure of the windows API. It then calls Application.Minimize in order to mimize all other forms. However, now the application button went back into the taskbar because it is no longer hidden but minimized. So the method hides it again. Now everything has gone away from the taskbar - leave out the last line of the SC_MINIMIZE part to see it. So the method again minimizes the form which will put it back into the taskbar.
When the form is restored, it first calls Application.Restore to show all other forms. This does not restore the main form as it was minimized when Application.Minimize was called and so it is not restored. Then the form restores itself. Now the application's button is still in the taskbar because it was restored. So you have to hide it again.
All the lines that are marked with (**) can be left out if your application only uses one main form (I'm not sure, but I think you can also leave them out if the other forms are children of the main form, e.g. in a MDI application). Of course Forms that are only shown modally don't matter in this case as the application cannot be minimized when a modal form is active.