Get color of active window title bar in Delphi

This post shows you how to get the color of the title bar for the active window.  The method to get the color of the title bar of an active window in Delphi has changed over time.

In Windows 7 could get the color by using clActiveCaption but on WIndows 10 that no longer works but you can use the following code instead.

The title bar can have two colours fading from left to right.

I have provided function to get the left and right color and to determine if the right color is used or not

unit zzColorU;

interface

uses Vcl.Graphics;

function zzGetWindowTitleBarPrimaryColor : TColor;
  // return the primary color of the title bar in active windows

function zzGetWindowTitleBarSecondaryColor : TColor;
  // return the secondary (right hand side) gradiated color of the title bar in active windows

function zzGetWindowTitleBarIsGradiated : boolean;
  // return TRUE if the color of title bars for active windows is gradiated

implementation

uses WinApi.Windows;

// =================================

function zzGetWindowTitleBarPrimaryColor : TColor;
  // return the primary color of the title bar in active windows
begin
          // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
  result := WinApi.Windows.GetSysColor (WinApi.Windows.COLOR_ACTIVECAPTION)
end;

// =================================

function zzGetWindowTitleBarSecondaryColor : TColor;
  // return the secondary (right hand side) gradiated color of the title bar in active windows
begin
          // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
  result := WinApi.Windows.GetSysColor (WinApi.Windows.COLOR_GRADIENTACTIVECAPTION);
end

// =================================

function zzGetWindowTitleBarIsGradiated : boolean;
  // return TRUE if the color of title bars for active windows is gradiated
var
  vUseGradient : boolean;
begin
  result := FALSE;
  if (SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, @vUseGradient, 0)) then
      if (vUseGradient) then
          result := TRUE;
end;

// =================================

end.

 

About Me

scott_hollows_201611

  • Oracle & Delphi software developer based in Perth, Western Australia
  • Australian Delphi User Group – President and WA meeting organizer
  • Australian Oracle User Group – WA State Committee Member
  • Available to do remote presentations to user groups on Delphi and Oracle topics
blog email linkedinlogo

 

 

Author: Scott Hollows

Enterprise software developer based in Perth, Western Australia. Oracle, Delphi, Data Warehouse design and ETL, Data Architect, Business Intelligence, Oracle performance tuning. Oracle ApEx, Discoverer, BI Publisher, OBIEE, Forms, Reports, SQL, PLSQL Australian Delphi User Group (ADUG) - WA branch manager and past national president LinkedIn www.linkedin.com/in/scotthollows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s