Solved

Change windows title color!

Posted on 2002-04-02
7
228 Views
Last Modified: 2010-04-04
I like to know how to change the form's title color (background of caption).

Thanks.
0
Comment
Question by:jlislo
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6914064
the most simple way is to get some TCaptionBar component :)
check this : http://www.torry.net/captions.htm
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 50 total points
ID: 6914239
try this from Neil Rubenkings book, Delphi Programming Problem Solver. (ISBN 1-56884-795-5).

unit Mytitleu;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure DrawTitle(IsActive: Boolean ;const S : String);
    procedure WMNCPaint(VAR Msg: TWMNCPaint);
      message WM_NCPAINT;
    procedure WMNCActivate(VAR Msg: TWMNCActivate);
      message WM_NCACTIVATE;
    procedure WMSetText(VAR Msg: TWMSetText);
      message WM_SETTEXT;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
{$R *.DFM}

implementation

procedure TForm1.DrawTitle(IsActive: Boolean ;const S : String);
VAR
  TopOfs: Word;
  R: TRect;
  XF,            {frame width}
  YF,            {frame height}
  XS,            {caption bar button width}
  YS: Integer;  {caption bar button height}
begin
  XF := GetSystemMetrics(SM_CXFRAME);
  YF := GetSystemMetrics(SM_CYFRAME);
  XS := GetSystemMetrics(SM_CXSIZE);
  YS := GetSystemMetrics(SM_CYSIZE);
  WITH Canvas DO
    try
      R := Bounds(XF, YF, ClientWidth, YS);
      R.Right := R.Right-XS-1;
      IF biSystemMenu IN BorderIcons THEN R.Left := R.Left+XS+1;
      IF biMinimize IN BorderIcons THEN R.Right := R.Right-XS-1;
      IF biMaximize IN BorderIcons THEN R.Right := R.Right-XS-1;
      Handle := GetWindowDC(Self.Handle);
      Brush.Color := clGreen;
      Font.Color  := clBlack;
      Font.Style  := [];
      Font.Name   := 'Times New Roman';
      TopOfs := TextHeight(S);
      IF TopOfs > YS THEN TopOfs := 0
      ELSE TopOfs := (YS-TopOfs) DIV 2;
      SetTextAlign(Handle, TA_CENTER);
      TextRect(R, (R.Right+R.Left) div 2, R.Top+TopOfs, S);
    finally
      ReleaseDC(Self.Handle, Handle);
      Handle := 0;
    end;
end;

procedure TForm1.WMNCPaint(VAR Msg: TWMNCPaint);
BEGIN
  Inherited;
  DrawTitle(Active, Caption);
END;

procedure TForm1.WMNCActivate(VAR Msg: TWMNCActivate);
BEGIN
  Inherited;
  DrawTitle(Msg.Active, Caption);
END;

procedure TForm1.WMSetText(VAR Msg: TWMSetText);
BEGIN
  Inherited;
  DrawTitle(Active, Caption);
END;

end.

Regards,
Steve
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6915006
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.

 

Author Comment

by:jlislo
ID: 6915294
Thank you all for the help. I find a simple way to do this, please see the followinf code

------------------------------------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure SetColor ;
    procedure RestoreColor ;
  public
    { Public declarations }
  end;


var
  Form1: TForm1;
  oldColorValue,ColorValue: array [1..5] of longint;
  ColorIndex: array [1..5] of integer;

implementation

{$R *.DFM}

procedure TForm1.SetColor;
begin
  ColorIndex[1] := COLOR_ACTIVECAPTION   ;
  ColorValue[1] := strtoint('$0000FF')   ;

  SetSysColors(1,ColorIndex,ColorValue);
  PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.RestoreColor;
begin
  ColorIndex[1] := COLOR_ACTIVECAPTION   ;
  ColorValue[1] := oldcolorvalue[1];
  SetSysColors(1,ColorIndex,ColorValue);
  PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   oldColorValue[1] := GetSysColor(COLOR_ACTIVECAPTION );
   Application.OnActivate := FormActivate ;
   Application.OnDeactivate := FormDeactivate ;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
   SetColor ;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
   RestoreColor ;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   RestoreColor ;
   Application.OnActivate := nil ;
   Application.OnDeactivate := nil ;
end;


end.
 
0
 

Author Comment

by:jlislo
ID: 6915711
I find the answer myself. Thanks.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6915797
ummmm
well you already lost the 50 points assigned to this q
so you might as well give them away ...
and it's not about the points .. it's the attitude
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6919217
Many thanks, jlislo.

Steve
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

16 Experts available now in Live!

Get 1:1 Help Now