Title: Form with custom caption bar
Question: How to remove system caption bar (title bar) or replace it by my own?
Answer:
There is another way to address a problem discussed in Article 901.
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.
--------------------------------------
unit DPCCForms;
interface
uses
Windows, Messages, Classes, Controls, Forms;
type
TDPCCForm = class (TForm)
private
{ Private declarations }
FCaptionControl: TGraphicControl;
procedure WMNCHitTest (var AMessage: TWMNCHitTest); message WM_NCHITTEST;
protected
procedure CreateParams (var Params: TCreateParams); override;
public
{ Public declarations }
property CaptionControl: TGraphicControl
read FCaptionControl write FCaptionControl default NIL;
end;
{===============================================================}
implementation
{---------------------------------------------------------------}
procedure TDPCCForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams (Params);
with Params do begin
Style := (Style OR WS_POPUP) AND (NOT WS_DLGFRAME);
end; {with}
end {--TDPCCForm.CreateParams--};
{---------------------------------------------------------------}
procedure TDPCCForm.WMNCHitTest (var AMessage: TWMNCHitTest);
begin
inherited;
if ((AMessage.Result = HTCLIENT) AND
Assigned (CaptionControl) AND
PtInRect (CaptionControl.BoundsRect,
ScreenToClient (Point (AMessage.XPos,
AMessage.YPos)))) then begin
AMessage.Result := HTCAPTION;
end; {if}
end; {--TDPCCForm.WMNCHitTest--}
end.