Einzelnen Beitrag anzeigen

Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Komponente informieren, wenn Formular - Caption / Icon g

  Alt 12. Dez 2005, 20:17
als eigene Komponente würde das so aussehen:
Delphi-Quellcode:
unit uCustomTitleBar;

interface

uses
  windows, graphics, classes, Controls, Forms, messages;

type
  TCustomTitleBar = class(TCustomControl)
  protected
    procedure SetParent(AParent: TWinControl); override;
  private
    fBGPic: TBitmap;
    fNeedsRecreate: Boolean;
    fOldMethod: TWndMethod;
    procedure FCreateBGPic;
    procedure FNewWndProc(var AMsg: TMessage);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure Paint; override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  end;

implementation

procedure TCustomTitleBar.SetParent(AParent: TWinControl);
var LForm: TCustomForm;
begin
  if AParent <> Parent then
  begin
    if Parent <> nil then
    begin
      LForm := GetParentForm(Self);
      LForm.WindowProc := fOldMethod;
    end;
    inherited SetParent(AParent);
    if Parent <> nil then
    begin
      LForm := GetParentForm(Self);
      fOldMethod := LForm.WindowProc;
      LForm.WindowProc := FNewWndProc;
    end;
  end;
end;


constructor TCustomTitleBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fBGPic := TBitmap.Create;
  fNeedsRecreate := True;
  SetBounds(0, 0, 100, 100);
end;

destructor TCustomTitleBar.Destroy;
begin
  Parent := nil;
  fBGPic.Free;
  inherited Destroy;
end;

procedure TCustomTitleBar.Paint;
begin
  if fNeedsRecreate then
    FCreateBGPic;
  BitBlt(Canvas.Handle, 0, 0, Width, Height, fBGPic.Canvas.Handle, 0, 0, SRCCOPY);
end;

procedure TCustomTitleBar.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var LResized: Boolean;
begin
  LResized := (AWidth <> Width) or (AHeight <> Height);
  inherited;
  fNeedsRecreate := True;
  Repaint;
end;

procedure TCustomTitleBar.FCreateBGPic;
begin
  fBGPic.Width := Width;
  fBGPic.Height := Height;
  fBGPic.Canvas.Brush.Color := clBlue;
  fBGPic.Canvas.FillRect(Rect(0, 0, fBGPic.Width, fBGPic.Height));
  fBGPic.Canvas.TextOut(0, 0, GetParentForm(Self).Caption);
  fNeedsRecreate := False;
end;

procedure TCustomTitleBar.FNewWndProc(var AMsg: TMessage);
begin
  fOldMethod(AMsg);
  if (AMsg.Msg = WM_SETTEXT) then
    Repaint;
end;


end.
Das malen passiert im FCreateBGPic. Also dort einfach den gewünschten Paint-Source einfügen.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat