Author: Jonas Bilinkevicius
How to roll up and restore a TForm when clicking on the title bar
Answer:
The standard behaviour for double clicking a title bar is to maximize/ restore the
form. The following class changes the double click action to add a new effect which
is RollUp/ Restore. Copy the following unit and place it in a directory which is
recognised by Delphi's search path.
1 unit OrckaForm;
2 3 interface4 5 {$B-}6 7 uses8 Messages, Forms, Classes;
9 10 type11 TOrckaForm = class(TForm)
12 private13 FOldHeight: Longint;
14 FRollUp, FRolledUp: Boolean;
15 protected16 procedure WMNCLDblClick(var Msg: TMessage); message WM_NCLBUTTONDBLCLK;
17 procedure WMGetMinMaxInfo(var Msg: TMessage); message WM_GETMINMAXINFO;
18 public19 constructor Create(AOwner: TComponent); override;
20 property RollUp: Boolean read FRollUp write FRollUp;
21 end;
22 23 implementation24 25 uses26 Windows;
27 28 procedure TOrckaForm.WMNCLDblClick(var Msg: TMessage);
29 begin30 if (Msg.wParam = HTCAPTION) and (FRollUp) then31 begin32 if FRolledUp then33 begin34 FRolledUp := False;
35 Height := FOldHeight;
36 end37 else38 begin39 FRolledUp := True;
40 FOldHeight := Height;
41 Height := 0
42 end;
43 end44 else45 inherited;
46 end;
47 48 constructor TOrckaForm.Create(AOwner: TComponent);
49 begin50 inherited Create(AOwner);
51 FOldHeight := Height;
52 FRollUp := True;
53 FRolledUp := False;
54 end;
55 56 procedure TOrckaForm.WMGetMinMaxInfo(var Msg: TMessage);
57 begin58 inherited;
59 if FRolledUp then60 pMinMaxInfo(Msg.lParam)^.ptMaxTrackSize.y := Height;
61 end;
62 63 end.
64 65 //To use the form create a new form which will look something like..66 67 unit Unit3;
68 69 interface70 71 uses72 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
73 74 type75 TForm3 = class(TForm)
76 private77 { Private declarations }78 79 //Add OrckaForm to the uses clause and change the following line80 81 TForm3 = class(TForm)
82 83 //to84 85 TForm3 = class(TOrckaForm)
Run your project, whenever you double click the title the form will roll up/ restore.