Solved

Change windows title color!

Posted on 2002-04-02
7
241 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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