Author: Jonas Bilinkevicius
My application is a non-MDI application. We use form.showmodal to call our
application forms because we do not want more than one window at a time to be open.
Problem: When our users minimize a window opened with showmodal, instead of
minimizing the application, the showmodal window is minimized on the desktop. We
need to restrict multiple windows from being open simultaneously in this
application.
Answer:
Have a look at this unit, this form will do what you want. When minimizing the
modal form it will minimize the app, and when restoring from the taskbar it will
restore the app and bring the modal window back to front.
1 unit testunit;
2
3 interface
4
5 uses
6 Forms, SysUtils, Windows, Messages, Classes, Graphics, Controls, Dialogs,
7 StdCtrls;
8
9 type
10 TFormTest = class(TForm)
11 private
12 { Private declarations }
13 OldRestore: TNotifyEvent;
14 procedure MyMinimize(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
15 procedure DoRestore(Sender: TObject);
16 public
17 { Public declarations }
18 end;
19
20 implementation
21
22 {$R *.DFM}
23
24 procedure TFormTest.MyMinimize(var msg: TWMSysCommand);
25 begin
26 if (msg.cmdtype and $FFF0) = SC_MINIMIZE then
27 begin
28 { the following line only for D5, not for D3, due to a bug(?) in forms.pas }
29 EnableWindow(Application.handle, true);
30 Application.Minimize;
31 OldRestore := Application.OnRestore;
32 Application.OnRestore := DoRestore;
33 msg.Result := 0;
34 end
35 else
36 inherited;
37 end;
38
39 procedure TFormTest.DoRestore(Sender: TObject);
40 begin
41 Application.OnRestore := OldRestore;
42 SetForegroundWindow(Handle);
43 end;
44
45 end.
|