Author: Dmitri Papichev
How to remove system caption bar (title bar) or replace it by my own?
Answer:
Below you can find the source code of a unit that performs the task (note that it
is not a form). All you need is to inherit your form from TDPCCForm instead of
TForm. Property CaptionControl is accessible at run time and defines the control
(TGraphicControl) which acts as a caption bar. Usually you assign CaptionControl
once in OnCreate event handler of you form, but nothing prevents you from further
changes of CaptionControl at run time. If you leave CaptionControl unassigned, the
form will have no caption functionality at all.
1 unit DPCCForms;
2 3 interface4 5 uses6 Windows, Messages, Classes, Controls, Forms;
7 8 type9 TDPCCForm = class(TForm)
10 private11 { Private declarations }12 FCaptionControl: TGraphicControl;
13 procedure WMNCHitTest(var AMessage: TWMNCHitTest); message WM_NCHITTEST;
14 protected15 procedure CreateParams(var Params: TCreateParams); override;
16 public17 { Public declarations }18 property CaptionControl: TGraphicControl
19 read FCaptionControl write FCaptionControl defaultnil;
20 end;
21 22 {===============================================================}23 implementation24 25 {---------------------------------------------------------------}26 27 procedure TDPCCForm.CreateParams(var Params: TCreateParams);
28 begin29 inherited CreateParams(Params);
30 with Params do31 begin32 Style := (Style or WS_POPUP) and (not WS_DLGFRAME);
33 end; {with}34 end{--TDPCCForm.CreateParams--};
35 36 {---------------------------------------------------------------}37 38 procedure TDPCCForm.WMNCHitTest(var AMessage: TWMNCHitTest);
39 begin40 inherited;
41 if ((AMessage.Result = HTCLIENT) and42 Assigned(CaptionControl) and43 PtInRect(CaptionControl.BoundsRect,
44 ScreenToClient(Point(AMessage.XPos,
45 AMessage.YPos)))) then46 begin47 AMessage.Result := HTCAPTION;
48 end; {if}49 end; {--TDPCCForm.WMNCHitTest--}50 51 end.