Solved

Change windows title color!

Posted on 2002-04-02
7
246 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
[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
  • +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
Technology Partners: 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!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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