Mega Code Archive

 
Categories / Delphi / Forms
 

Custom CaptonBar

Title: Custom CaptonBar Question: How to create custom captionbar, and make an object become a captionbar? Answer: You can remove standard captionbar and replace it with yours like in this example: ------------------------------------------------------------------------- unit custom; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts, ExtCtrls, StdCtrls, Buttons, Menus; type TPopup = class(TForm) image1: TImage; procedure FormCreate(Sender: TObject); private FCaptionControl: TGraphicControl; procedure WMNCHitTest (var Message: TWMNCHitTest); message WM_NCHITTEST; protected procedure CreateParams (var Params: TCreateParams); override; public property CaptionControl: TGraphicControl read FCaptionControl write FCaptionControl default NIL; end; var Popup: TPopup; implementation {$R *.DFM} procedure TPopup.CreateParams(var Params: TCreateParams); begin inherited CreateParams (Params); with Params do begin Style := (Style OR WS_POPUP) AND (NOT WS_DLGFRAME); end; end; procedure TPopup.WMNCHitTest (var Message: TWMNCHitTest); begin inherited; if (Message.Result = HTCLIENT) then begin if Assigned (CaptionControl) then begin if ((CaptionControl.Left (CaptionControl.Top (CaptionControl.Left + CaptionControl.Width = Message.XPos - Left) AND (CaptionControl.Top + CaptionControl.Height = Message.YPos - Top)) then begin Message.Result := HTCAPTION; end; end; end; end; procedure TPopup.FormCreate(Sender: TObject); begin captioncontrol:= image1; end; end. -------------------------------------------------------------------------