2004. február 27., péntek
Roll up and restore a TForm when clicking on the title bar
Problem/Question/Abstract:
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.
unit OrckaForm;
interface
{$B-}
uses
Messages, Forms, Classes;
type
TOrckaForm = class(TForm)
private
FOldHeight: Longint;
FRollUp, FRolledUp: Boolean;
protected
procedure WMNCLDblClick(var Msg: TMessage); message WM_NCLBUTTONDBLCLK;
procedure WMGetMinMaxInfo(var Msg: TMessage); message WM_GETMINMAXINFO;
public
constructor Create(AOwner: TComponent); override;
property RollUp: Boolean read FRollUp write FRollUp;
end;
implementation
uses
Windows;
procedure TOrckaForm.WMNCLDblClick(var Msg: TMessage);
begin
if (Msg.wParam = HTCAPTION) and (FRollUp) then
begin
if FRolledUp then
begin
FRolledUp := False;
Height := FOldHeight;
end
else
begin
FRolledUp := True;
FOldHeight := Height;
Height := 0
end;
end
else
inherited;
end;
constructor TOrckaForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOldHeight := Height;
FRollUp := True;
FRolledUp := False;
end;
procedure TOrckaForm.WMGetMinMaxInfo(var Msg: TMessage);
begin
inherited;
if FRolledUp then
pMinMaxInfo(Msg.lParam)^.ptMaxTrackSize.y := Height;
end;
end.
To use the form create a new form which will look something like..
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm3 = class(TForm)
private
{ Private declarations }
Add OrckaForm to the uses clause and change the following line
TForm3 = class(TForm)
to
TForm3 = class(TOrckaForm)
Run your project, whenever you double click the title the form will roll up/ restore.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése