Mega Code Archive

 
Categories / Delphi / Forms
 

Minimize a Modal Window in Delphi 5

Title: Minimize a Modal Window in Delphi 5 Question: How can I get a Modal Window to Minimize like it did in Delphi 4? Answer: When a Window has been created using ShowModal, then using: Application.Minimize; in a Menu or Button, or having the following in the Modal Form's Declartion: procedure SysMen (var Msg: TMessage); message WM_SYSCOMMAND; and then in the implementation procedure TModalForm.SysMen (var Msg: TMessage); begin if Msg.wParam = SC_MINIMIZE then ShowWindow (Application.Handle, SW_MINIMIZE) else Inherited; end; caused the Application to Minimize when the Modal Window was Minimized. However when D5 had the Animation fixed this caused this behaviour to stop, so Minimizing the Modal form no longer causes the Application to Minimize. To fix, do the following in the MAIN FORM of your Application: To the Form Declaration add: procedure AppMinimize(Sender: TObject); procedure AppRestore(Sender: TObject); and in it's implementation: procedure TMainForm.AppMinimize(Sender: TObject); begin ShowWindow (Application.Handle, SW_MINIMIZE); end; procedure TMainForm.AppRestore(Sender: TObject); begin ShowWindow (Application.Handle, SW_RESTORE); end; procedure TMainForm.FormCreate(Sender: TObject); begin Application.OnMinimize := AppMinimize; Application.OnRestore := AppRestore; ... end; And you should find that your Modal Forms can now minimize the Application AND you get Animations where applicable.