Click here to Skip to main content
15,867,943 members
Articles / Desktop Programming / MFC
Article

XP Themes Tab Control in any orientation

Rate me:
Please Sign up or sign in to vote.
4.59/5 (34 votes)
6 Mar 20044 min read 310.2K   11.8K   112   56
How to make XP Themes Tab Control work properly in other than top orientation.

XPTabApp Image Using CXPTabCtrl

Using CXPTabCtrl, XP Themes Tab Control, left, bottom and right orientation

Introduction

The article shows how to solve a problem, which appears on the Windows Tab Control when using Windows XP operating system with XP Themes enabled. Tab control behaves as if it has only one orientation - top. In fact, it has all four orientations, but all four of them (for some reason) have the same appearance.

It is demonstrated how to use the proposed class CXPTabCtrl, Windows tab control extension as a solution to this problem. CXPTabCtrl detects the operating system and tab control orientation:

  • If it is not XP system or XP Themes are not enabled - it uses default Windows tab behavior (it does not do anything extra).
  • If it is XP system and XP Themes are enabled - it draws tab control properly in appropriate direction.

CXPTabCtrl control also works properly if the state of XP Themes enabling is changed during the running of the application. Tab control hot tracking is also supported.

Background

There are a lots of Windows applications developed for earlier Windows versions, which use bottom or other "not-top" oriented Windows tab control. The problem is: if the application is running on an XP system with XP Themes, Windows tab control is not shown properly as it used to be.

XPTabApp Image default SysTabControl32

Problems when using default SysTabControl32 (CTabCtrl) with XP Themes, bottom orientation

One possibility to solve this problem is to change all tab controls in these applications to be top oriented. This would involve change of the look of the applications and painful Windows resource changes and possible code changes.

Another possibility (used for CXPTabCtrl) is to use a thin wrapper around the tab control and to simulate missing orientations. CXPTabCtrl uses available XP Themes "top-tab" look as a template and adapts it for other tab orientations:

  • Bottom orientation:
    1. use top background bitmap,
    2. mirror it vertically,
    3. draw icon and text on mirrored background.

    Build CXPTabCtrl bottom orientation

  • Left orientation:
    1. use top background bitmap,
    2. draw icon and text on the background,
    3. rotate the bitmap for 90°.

    Build CXPTabCtrl left orientation

  • Right orientation:
    1. use top background bitmap,
    2. mirror it vertically,
    3. draw icon and text on the background,
    4. rotate the bitmap for 90°.

    Build CXPTabCtrl right orientation

  • Top orientation (used only for test purposes, could use default from XP Themes Windows XP):
    1. use top background bitmap,
    2. draw icon and text.

    Build CXPTabCtrl top orientation

Notice also that the body of the tab control has to be manipulated, mirrored or rotated, not only the "tab" parts of the tab control (because a "tab body" has texture and shadows).

How to use it

The CXPTabCtrl class is simple to use. To add it to your project, please follow the steps below:

  1. Put its source files (XPTabCtrl.cpp and XPTabCtrl.h) into the proper project folder and add their file names to your Visual Studio project.
  2. Include its header to the appropriate header file - usually dialog class header where class CXPTabCtrl is used. If you plan to use CXPTabCtrl in several places of your application, you can add it only to your StdAfx.h file:
    #include "XPTabCtrl.h"
  3. You should replace CTabCtrl with CXPTabCtrl everywhere in the project where you want new XP Themes tab behavior.
    CXPTabCtrl  m_tabCtrl
  4. If CXPTabCtrl has images, then appropriate bitmap IDB_TABIMAGES (or other with correct tab images) should be included as resource bitmap. It is also necessary to call InitImageList(IDB_TABIMAGES) function, from OnInitDialog or other appropriate initializing place:
    m_tabCtrl.InitImageList(IDB_TABIMAGES);
    // only necessary to call if tabs have images

Although tab control orientation is usually set in resource editor or in Tab's Create function, CXPTabCtrl orientation can be changed any time while application is running.

Points of Interest

This sample could also be used as an example of how to solve some other problems in Windows programming. Other techniques shown in this sample include:

  1. How to mirror bitmap image vertically fast and simply by using only two Windows calls GetDIBits and SetDIBits. This works in any color resolution.
  2. How to rotate rectangular bitmap image fast and in any color resolution.
  3. How to use inline assembler for lengthy repetitive processing, in this case, rotating bitmap image pixels. If image is of large dimensions (large tab control body), a C style coding could take considerable more time than assembler version.
  4. How to use XP Themes functions in applications, which can run on earlier operating systems.
  5. How to enable XP Themes dialog texture background.
  6. How to make applications XP Themes aware by simply copying XP manifest, resource "24", ID "1" from one application resource to another.
  7. How to use tab ToolTips.

Please note

  • The sample is created and compiled on VC++ 6.0 service pack 5.
  • The sample has been tested on Windows XP (XP Themes enabled or disabled while sample was running).
  • The sample has also been tested on Windows 2000, Windows NT 4.0 (CXPTabCtr does not have effect).
  • Other Windows systems could have possible problems (?)
  • The sample has been tested on the following color resolutions: 8 bit, 16 bit, 24 bit and 32 bit colors.
  • The sample has not been tested on multi-line (stacked) tabs, could be problems (?)

Correspondence

Please post your questions, suggestions and bug reports only to the forum below.

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


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalcontrol repaint very slowly Pin
Dzungcs24-Oct-08 22:00
Dzungcs24-Oct-08 22:00 
GeneralRe: control repaint very slowly Pin
Dzungcs24-Oct-08 22:04
Dzungcs24-Oct-08 22:04 
GeneralTab Control on Dialog Box using ATL Pin
JPMPHOENIX10-Aug-07 15:20
JPMPHOENIX10-Aug-07 15:20 
GeneralExremely difficult code to follow [modified] Pin
Alïen6-Jul-07 1:34
Alïen6-Jul-07 1:34 
GeneralRe: Exremely difficult code to follow Pin
Randor 29-Aug-07 21:04
professional Randor 29-Aug-07 21:04 
GeneralIncorrect drawing at many tabs Pin
basti27111-Jul-07 23:49
basti27111-Jul-07 23:49 
GeneralVerticalTab Crash [modified] Pin
MadAlbert19-Jun-07 20:38
MadAlbert19-Jun-07 20:38 
QuestionTmobile code? Pin
Msftone8-Apr-07 16:42
Msftone8-Apr-07 16:42 
GeneralOwner drawn tab control problem in Vista Pin
Ramya_Indian6922-Mar-07 23:14
Ramya_Indian6922-Mar-07 23:14 
GeneralPure win32 port. Pin
adel amro10-Feb-07 3:41
adel amro10-Feb-07 3:41 
QuestionWhy so many CRects to get the Tab Control dimensions ? Pin
erajsri17-Jan-07 7:23
erajsri17-Jan-07 7:23 
QuestionNo highlight when pointing to other tab Pin
davidlks16-Jul-06 3:14
davidlks16-Jul-06 3:14 
Generaleditable tab item Pin
PaulaPaziani4-May-06 9:21
PaulaPaziani4-May-06 9:21 
GeneralRefresh Problem Pin
smo7k15-Jul-05 17:46
smo7k15-Jul-05 17:46 
Generalproblem with vertical tab Pin
Hamid Reza Mohammadi1-Jul-05 19:23
Hamid Reza Mohammadi1-Jul-05 19:23 
GeneralRe: problem with vertical tab Pin
erajsri11-Feb-07 23:00
erajsri11-Feb-07 23:00 
GeneralDefault status Pin
Paper#15-Jun-05 7:06
Paper#15-Jun-05 7:06 
GeneralLooking for latest updated sources Pin
bfigg9722921-Apr-05 11:02
bfigg9722921-Apr-05 11:02 
GeneralXP Theme using Manifest ?! Pin
Master^Tristar7-Feb-05 6:07
Master^Tristar7-Feb-05 6:07 
GeneralRe: XP Theme using Manifest ?! Pin
David Pritchard20-Apr-05 8:40
David Pritchard20-Apr-05 8:40 
GeneralVertical Bug Pin
keternal26-Dec-04 21:11
keternal26-Dec-04 21:11 
Generalmemory leak Pin
Paul Heil7-Dec-04 6:34
Paul Heil7-Dec-04 6:34 
GeneralUsing true color images on tabs Pin
MMaker30-Nov-04 20:58
MMaker30-Nov-04 20:58 
Here's a fix so that true color images can be displayed on the tabs

void CXPTabCtrl::InitImageList(UINT nBitmapID, int nImageCount/*=0*/)
{
if(!::IsWindow(GetSafeHwnd()) || m_ilTabs.operator HIMAGELIST()){
ASSERT(FALSE);
return;
}

CBitmap bitmap;
if(bitmap.LoadBitmap(nBitmapID)){
BITMAP bmp;
if(bitmap.GetBitmap(&bmp)){
if(!nImageCount)
nImageCount = bmp.bmWidth / bmp.bmHeight; // use square images
if(m_ilTabs.Create(bmp.bmWidth / nImageCount, bmp.bmHeight, ILC_COLORDDB | ILC_MASK , nImageCount, 1)){
m_ilTabs.Add(&bitmap, RGB(255,0,255)); // transparency color magenta
SetImageList(&m_ilTabs);
return; // ok
}
}
}
ASSERT(FALSE); // error
}

Questionanyone fixed left orientation with themes disabled ? Pin
freddycam1-Nov-04 23:52
freddycam1-Nov-04 23:52 
GeneralAdding pages Pin
Steve Kelly28-May-04 5:37
Steve Kelly28-May-04 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.