Link to home
Start Free TrialLog in
Avatar of pr_wainwright
pr_wainwright

asked on

Change form Caption bar Colour/Font

Is it possible to change a forms caption (title) bar colour and font using Windows API. I can use RxLib's Gradient caption component but would like to do this using API only.

Thanks
Paul.
Avatar of alanwhincup
alanwhincup

There is a lot of code involved with this so I'm just going to point you to:

www.torry.net/captions.htm

You can find the source code for components that add a gradient to the caption bar of your form and more.

Cheers,

Alan
ASKER CERTIFIED SOLUTION
Avatar of bugroger
bugroger

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pr_wainwright

ASKER

Bugroger,
         Your code works fine for fonts. Any idea's on how to change the colour of the title bar ?. Solid colour required, no gradient necessary.

Thanks
Paul.
hi pr

 i think there is no api function to change the
 color of a window's caption! You only can change the
 system colors. But then all window captions will be
 changed.

 Look at:
 http://www.mindspring.com/~cityzoo/ttlbar1.html
 
 It's an artikel about
 Creating Forms with Custom Title Bars

 maybe it helps

GL
 bug
Heres a bit of code to get you started:

...
  private
    { Private declarations }
    procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
  public
    { Public declarations }
  end;

...

procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
var
  cxWin, cxBit, cxFrame,  cyBit, cyCapt, cyFrame : Integer;
  Rect : TRect;
  H : hdc;
begin
  inherited;
  cxBit := GetSystemMetrics(SM_CXSIZE);
  cxFrame := GetSystemMetrics(SM_CXFRAME);
  cyCapt := GetSystemMetrics(SM_CYCAPTION);
  cyFrame := GetSystemMetrics(SM_CYFRAME);
  GetWindowRect(Form1.Handle, Rect);
  cxWin := rect.Right - Rect.Left;
  Rect.Top := cyFrame;
  Rect.Bottom := Rect.Top + cyCapt - 2;
  Rect.Left := cxFrame + cxBit + 1;
  Rect.Right := cxWin - cxFrame - 2 * cxBit - 2;
  H := GetWindowDC(Form1.Handle);
  FillRect(H, Rect, CreateSolidBrush(RGB(255, 0, 0)));
  SetBkMode(H, TRANSPARENT);
  SetTextColor(H, clBlack);
  DrawText(H, PChar(Form1.Caption), -1, Rect, DT_LEFT);
  ReleaseDc(Form1.Handle, H);
end;

It paints MOST of the caption bar red (all except around the buttons). This is because to make it look like the whole caption bar is red would mean to paint the buttons and system images over the top of the background manually. Also there are other problems such as when the window becomes inactive and when the window is restored. I will try and code a better working example for you and will post it later on.

Cheers,

Alan
Bugroger,
         Thanks for the source code & link.

Regards
Paul.