Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change form Caption bar Colour/Font

Posted on 2002-07-05
6
Medium Priority
?
633 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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

824 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