Delphi: Minimising child forms in an SDI application
In an SDI application (Single Document Interface), the main form acs as the “container” for the entire application. This means that child forms, are exactly that – children of the application. The long and short of which, means that when you minimise the main form of the application, all forms are hidden. In addition to which, when you minimise a child form of the application, it doesn’t minimise to the task bar, instead it minimises to the application desktop. This also has the side effect that only the main application form itself has a task bar button.
So, How do I change this behaviour?
For one reason or another, you may decide that you want to let each child form in an application you create have it’s own Task Bar button, and as a result, complete control over it’s visibility when the application’s main form is minimized/restored. Ordinarily, the first form created in your application is the Main Form. It is the parent of all other forms that will be created in your application, and as such, when the main form closes, the application terminates. In addition, when the main form is minimised, all child forms are also minimized as the application is hidden. Only the main form in this case has a button on the task bar.
So, you don’t really want your child forms to be hidden when you minimise the main form of the application…
Well, you need to do two things. Both can be done inside the CreateParams() method of your form. SO you’ll need to override this procedure.
Firstly, you’ll need to change the style parameters of the form when it is created. More specifically, you need to override the and manually set the ExStyle parameter. Secondly, you’ll need to change the parent of the form form the applications main form to something else – usually the Windows Desktop.
Firstly, you need to add the style WS_EX_APPWINDOW to the style of the window being created. You can do this by oring this constant with the ExStyle paramter as such:
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
So, the code would look like this:
interface
type
TChildForm = class(TForm)
...
protected
procedure CreateParams(var Params: TCreateParams); override;
...
implementation
procedure TChildForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;
end;
References:
http://delphi.about.com/od/formsdialogs/a/child_forms.htm
http://delphi.about.com/od/formsdialogs/l/aa073101a.htm




on January 28th, 2009 at 5:57 pm
Good work! Thank you very much!
I always wanted to write in my blog something like that. Can I take part of your post to my blog?
Of course, I will add backlink?
Sincerely, Timur I.
on June 14th, 2011 at 8:53 pm
Thank you for your solution. Saved my time.