Delphi - Fenstertitelleiste selber zeichnen
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private-Deklarationen }
procedure WMNCPAINT(var Msg: TMessage); Message WM_NCPAINT;
procedure WMNCACTIVATE(var msg: TMessage); Message WM_NCACTIVATE;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
MYCAPTION = 'Meine zentrierte Fenster-Caption';
procedure PaintCaption(hWnd: THandle; WndCaption: String);
var
dc : HDC;
CaptRect, WndRect: TRect;
begin
dc := GetWindowDC(hWnd);
GetWindowRect(hWnd, WndRect);
CaptRect.Left := GetSystemMetrics(SM_CXEDGE);
CaptRect.Top := GetSystemMetrics(SM_CYEDGE)+2;
CaptRect.Right := WndRect.right-WndRect.Left-GetSystemMetrics(SM_CYEDGE);
CaptRect.Bottom := GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYEDGE);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, RGB(255, 255, 255));
DrawText(dc, @WndCaption[1], lstrlen(@WndCaption[1]), CaptRect, DT_CENTER or DT_VCENTER);
ReleaseDC(hWnd, dc);
end;
procedure TForm1.WMNCPAINT(var Msg: TMessage);
begin
Inherited;
if msg.Msg = WM_NCPAINT then
begin
PaintCaption(Self.Handle, MYCAPTION);
end;
end;
procedure TForm1.WMNCACTIVATE(var msg: TMessage);
begin
Inherited;
if msg.Msg = WM_NCACTIVATE then
PaintCaption(Self.Handle, MYCAPTION);
end;
end.