PROCEDURE TMain.DrawCaption;
var FH,FW,CH,IH,IW,BW,X,Y:Integer; Bmp:TBitMap; Canvas:TCanvas; R:TRect;
Metrics:TNONCLIENTMETRICS;
begin
if WindowState=wsMinimized
then Exit;
if CaptionState=csNothing
then Exit;
Canvas:=TCanvas.Create;
Canvas.Handle:=GetWindowDC(Self.Handle);
CH:=GetSystemMetrics(SM_CYCAPTION)-1;
// Unten scheint ein Pixel zu fehlen
BW:=3*GetSystemMetrics(SM_CXSize);
// W Buttons
// Rect der Caption, abzüglich der Minimize,Maximize,Close Buttons definieren
if WindowState=wsMaximized
then begin
SetRect(R,0,0,Width-BW,CH);
end else begin
FH:=GetSystemMetrics(SM_CYFRAME);
FW:=GetSystemMetrics(SM_CXFRAME);
SetRect(R,FW,FH,Width-FW-BW,FH+CH);
end;
// Icon in Bitmap kopieren
IH:=GetSystemMetrics(SM_CYSMICON);
// H Icon
IW:=GetSystemMetrics(SM_CXSMICON);
// W Icon
Bmp:=TBitMap.Create;
Bmp.Width:=IW;
Bmp.Height:=IH;
X:=R.Left+2;
Y:=(R.Top+R.Bottom-IH)
div 2;
BitBlt(Bmp.Canvas.Handle,0,0,IW,IH,Canvas.Handle,X,Y,srccopy);
// Canvas Hintergrund zeichen
with CaptionColors[CaptionState]
do
GradientFillCanvas(Canvas,BK1,BK2,R,gdHorizontal);
// Icon zeichnen
Canvas.Draw(X,Y,Bmp);
// Caption Text zeichnen
Inc(R.Left,2+IW+4);
Dec(R.Right,4);
Metrics.cbSize:=SizeOf(TNONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,Metrics.cbSize,@Metrics,0);
Canvas.Font.Height:=Metrics.lfCaptionFont.lfHeight;
Canvas.Font.Style:=[fsBold];
Canvas.Font.Color:=CaptionColors[CaptionState].FC;
Canvas.Brush.Style:=bsClear;
Y:=(R.Top+R.Bottom-Canvas.TextHeight('
'))
div 2;
Canvas.TextRect(R,R.Left,Y,Caption);
// Aufräumen
ReleaseDC(Self.Handle,Canvas.Handle);
Canvas.Free;
Bmp.Free;
end;