Author: Jonas Bilinkevicius
How to keep other forms visible while minimizing the main form
Answer:
Solve 1:
You need to disable Delphi's default minimization behaviour and take over yourself.
In the main forms FormCreate do this:
1 { ... }2 ShowWindow(Application.handle, SW_HIDE);
3 SetWindowLong(Application.handle, GWL_EXSTYLE, GetWindowLong(application.handle,
4 GWL_EXSTYLE) andnot WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
5 ShowWindow(Application.handle, SW_SHOW);
6 { ... }
That removes the application button from the taskbar.
The main form gets a handler for the WM_SYSCOMMAND message:
7 { ... }8 private{form declaration}9 10 procedure WMSyscommand(var msg: TWmSysCommand); message WM_SYSCOMMAND;
11 12 procedure TForm1.WMSyscommand(var msg: TWmSysCommand);
13 begin14 case (msg.cmdtype and $FFF0) of15 SC_MINIMIZE:
16 begin17 ShowWindow(handle, SW_MINIMIZE);
18 msg.result := 0;
19 end;
20 SC_RESTORE:
21 begin22 ShowWindow(handle, SW_RESTORE)
23 msg.result := 0;
24 end;
25 else26 inherited;
27 end;
28 end;
This disables the default minimization behaviour.
To get a taskbar button for the form and have it minimize to the taskbar instead of
to the desktop, override the CreateParams method of the main form and also of all
the secondary forms:
29 { in form declaration }30 31 procedure CreateParams(var params: TCreateParams); override;
32 33 procedure TForm1.CreateParams(var params: TCreateParams);
34 begin35 inherited CreateParams(params);
36 params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
37 end;
Solve 2:
You must override the CreateParams() method and add the following code:
38 39 procedure TForm2.CreateParams(var params: TCreateParams);
40 begin41 inherited CreateParams(Params);
42 Params.ExStyle := params.ExStyle or WS_EX_APPWINDOW
43 end;
Something to keep in mind is that when you restore a minimized form, the entire
application will be brought to the front If you don't want that to happen, do this:
44 45 procedure TForm3.CreateParams(var params: TCreateParams);
46 begin47 inherited CreateParams(Params);
48 Params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
49 Params.WndParent := GetDesktopWindow; {add this line}50 end;
Now the forms will brought to the front independently. If you're launching forms from other form, you'll have to handle the paranting issues accordingly so that modal forms don't appear behind your other forms.