Solved

Change form Caption bar Colour/Font

Posted on 2002-07-05
6
621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 15 hours left to enroll

622 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