Solved

Change windows title color!

Posted on 2002-04-02
7
226 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:jlislo
Comment Utility
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
Comment Utility
I find the answer myself. Thanks.
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
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
Comment Utility
Many thanks, jlislo.

Steve
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

11 Experts available now in Live!

Get 1:1 Help Now