A Technique to Customize the Title Bar of Windows

A Technique to Customize the Title Bar of Windows

 

Image 1

Image 2

Introduction

This uses a technique of customizing the title bar by simulating the window's title bar's behavior with a substitute window. The former window title bar is removed from the window region, and a substitute window which behaves just like a window title bar is created at the position where the window's title bar should be. The demo project provides a framework to achieve this job, and also two kinds of title bar looks: one is somewhat like window title bars on X Windows, and the other is my creation.

Background

I read a good article on customization of window's title bar through window subclassing written by James Brown. Soon I found that it is not so easy to achieve a complex visual effect that I want by the window subclassing technique. MS seems to not like programmers to change the default behavior of Windows user interface elements, thus many programmers have to "create" new user interface elements by themselves. This is an example of such a condition.

Classes

Titlebar: Derive your window classes that need title bar customization from this class, and specify a title bar substitute class and a button class as template arguments.

TitlebarSubstitute: The base class of the title bar's substitute window. This implements most of the window title bar's behavior. To achieve various visual effects, just derive your own substitute window class from it, and override its virtual methods. The most important virtual methods of TitlebarSubstitute is DoPaint, which is responsible for drawing all title bar elements except system buttons. There are two classes derived from TitlebarSubstitute in the demo project, LinuxTitlebarSubstitute which makes a window title bar like the first screenshot, and WrittenInMidnight like in the second screenshot.

PushButton: A custom-draw button class, the base class of all system buttons classes.

Using the Code

First, derive your window class from class Titlebar. For example:

 
class CMainFrame : public CFrameWindowImpl<CMAINFRAME>, public CUpdateUI<CMAINFRAME>, 
  public CMessageFilter, public CIdleHandler,
  public FreshUI::Titlebar <
    CMainFrame, FreshUI::LinuxTitlebarSubstitute <
      FreshUI::LinuxSystemButton > >

Chain a message map to class Titlebar:

 
typedef FreshUI::Titlebar <
  CMainFrame, FreshUI::LinuxTitlebarSubstitute <
    FreshUI::LinuxSystemButton > > baseClass;

BEGIN_MSG_MAP(CMainFrame)
    // ...
    CHAIN_MSG_MAP(baseClass)
END_MSG_MAP()

Call Titlebar::Init. For general windows, you should call this method in OnCreate; for dialogs, call it in OnInitDialog. For example:

 
LRESULT OnCreate(
  UINT /*uMsg*/,
  WPARAM /*wParam*/,
  LPARAM /*lParam*/,
  BOOL& /*bHandled*/)
{
  // ...
    
  // Initialize Titlebar
  Init();
  return 0;
}

History

  • 07-02-2003 - Initial upload

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

posted @ 2022-12-13 15:32  小风风的博客  阅读(25)  评论(0编辑  收藏  举报