Re: Changing the color of the active title bar



I did it like this, I had some problem drawing the system button so I
only painted up to the button.

in form type private declaration ...

procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
procedure WMActivate(var Msg : TWMActivate); message WM_ACTIVATE;

in implementation ...

// = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Draw Red Titlebar
// = = = = = = = = = = = = = = = = = = = = = = = = = = = =
procedure TForm1.WMNCPaint(var Msg : TWMNCPaint);
begin
inherited;
DrawCaption;
end;

procedure TForm1.WMActivate(var Msg : TWMActivate);
begin
inherited;
DrawCaption;
end;

procedure TForm1.DrawCaption;
var
xFrame, yFrame, xSize, ySize : Integer;
begin
{get titlebar dimensions}
xFrame := GetSystemMetrics(SM_CXFRAME);
yFrame := GetSystemMetrics(SM_CYFRAME);
xSize := Self.Width - yFrame;
ySize := yFrame + GetSystemMetrics(SM_CYCAPTION);
{allocate device context handle to form's canvas}
with Self.Canvas do begin
Handle := GetWindowDC(Self.Handle);
with Font do begin
Name := 'Arial';
Size := 9;
Color := clBlue;
Style := [fsBold];
end;
if Self.Active then
Brush.Color := clRed;
{fill titlebar except for close button}
FillRect(Rect(xFrame, yFrame, xSize - ySize + (xFrame div 2),
ySize));
TextOut(xFrame + 4, yFrame + 2, Self.Caption);
{release device context ...}{ and set the canvas handle to default}
ReleaseDC(Self.Handle, Handle);
{... set the canvas handle to nil}
Handle := 0;
end;
end;

Alan Lloyd

.


Quantcast