65.9K
CodeProject is changing. Read more.
Home

Title Bar Replacement Class With Cool Features

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.68/5 (16 votes)

Oct 4, 2006

1 min read

viewsIcon

97273

downloadIcon

3252

Nice looking title bar for your applications with autohide and ghost-drag capabilities.

Sample Image - TBarDemo.gif

Introduction

This article describes an easy to use, drop-in MFC class which replaces the standard title bar.

Background

While creating an application with the Media Center 2005 look and feel, I noticed the title bar. I decided to recreate it and add it to one of my own ideas. I called it the "Ghost Drag". feature.

Environment

This project was built and tested on Windows 2000 and Windows XP using Visual Studio 6 SP5 and the Microsoft Platform SDK (Feb 2003).

Using the code


The TBar class can be easily added to your window/dialog with a few easy steps.

  1. Add "TBar.h" and "TBAR.cpp" to your project.
  2. Include  "TBar.h" in your main window/dialog class.
  3. Create a member variable of type CTBar.
  4. (Optional) Add caption button images to your project.
  5. In the window initialization, create and setup the new title bar:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // ...
    // Remove default menu
    SetMenu(NULL);

    // Create new title bar
    m_TBar.Create(this, ID_TBAR);    

    // Caption images are optional
    m_TBar.SetCloseBtnUpBmp(IDB_CAP_CLOSE_UP);
    m_TBar.SetCloseBtnDownBmp(IDB_CAP_CLOSE_DN); 
    m_TBar.SetMaxBtnUpBmp(IDB_CAP_MAX_UP);
    m_TBar.SetMaxBtnDownBmp(IDB_CAP_MAX_DN);
    m_TBar.SetResBtnUpBmp(IDB_CAP_RES_UP); 
    m_TBar.SetResBtnDownBmp(IDB_CAP_RES_DN);
    m_TBar.SetMinBtnUpBmp(IDB_CAP_MIN_UP);
    m_TBar.SetMinBtnDownBmp(IDB_CAP_MIN_DN);

// ...

History

  • Oct 4th 2006 - Origional article.
  • Oct 6th 2006 - Bugs fixed / features added.
    • Double clicking (maximize/restore) added.
    • Disabled dragging while in maximized state.
    • Added VS2003 solution file (TBarDemo.sln).
  • Oct 11th 2006 - Bugs fixed / features added.
    • Fixed bug regarding pressing one of the buttons and releasing the mouse outside of the window and the flickering problem.
    • Added (by request) the ability to remove the close button.