Solved

Change form Caption bar Colour/Font

Posted on 2002-07-05
6
615 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 58
what font behind pdf 32 128
How to renew a Delphi rad-studio licence? 5 49
Error E2158 compiling with Delphi XE10 Seattle 2 88
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now