Solved

Change form Caption bar Colour/Font

Posted on 2002-07-05
6
611 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:pr_wainwright
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7131523
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
0
 
LVL 2

Accepted Solution

by:
bugroger earned 100 total points
ID: 7131710
hi,

this function let you change the font of
the form's caption bar!

Function SetCaptionFont(FontName : String) : boolean;
Type
 con = array[0..31] of char;
Var
 NCM         : TNONCLIENTMETRICS;
begin
 Result     := false;
 ncm.cbSize := SizeOF(ncm);
 //Get old NCM
 IF SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize,  @ncm, 0) then
 begin
  //Set new FontName
  Move(PChar(FontName)[0], ncm.lfCaptionFont.lfFaceName[0], SizeOf(ncm.lfCaptionFont.lfFaceName));

  //Set new NCM
  IF SystemParametersInfo(SPI_SETNONCLIENTMETRICS, ncm.cbSize,  @ncm, 0) then
   Result := true;
 end;
end;


GL
 bug
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 7133261
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:bugroger
ID: 7133531
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
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7133671
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
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 7134035
Bugroger,
         Thanks for the source code & link.

Regards
Paul.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now