Using CXPTabCtrl, XP Themes Tab Control, left, bottom, and right orientation
1. Introduction
The article shows how to solve a problem that appears on the Windows Tab Control when using the Windows XP operating system with XP Themes enabled. The tab control behaves as 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
, a Windows tab control extension, as a solution to this problem. CXPTabCtrl
detects the operating system and tab control orientation:
- If it is not an XP system or XP Themes are not enabled, it uses the default Windows tab behaviour (it does not do anything extra).
- If it is an XP system and XP Themes are enabled, it draws the tab control properly in the appropriate direction.
The 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.
2. Method
There are a lot of Windows applications developed for earlier Windows versions that 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, the Windows tab control is not shown properly as it used to be.
Problems when using the 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 posssible code changes.
Another possibility (used for CXPTabCtrl
) is to use a thin wrapper around the tab control and to simulate missing orientations. CXPTabCtrl
uses the available XP Themes “top-tab” look as a template and adapts it for other tab orientations:
- Bottom orientation:
- Use a top background bitmap
- Mirror it vertically
- Draw icon and text on mirrored background
- Left orientation:
- Use top background bitmap
- Draw icon and text on the background
- Rotate the bitmap for 900.
- Right orientation:
- Use top background bitmap
- Mirror it vertically
- Draw icon and text on the background
- rotate the bitmap for 900.
- Top orientation (used only for test purposes, could use default from XP Themes Windows XP):
- Use top background bitmap
- Draw icon and text
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).
3. Programming Hints
The CXPTabCtrl
class is simple to use. To add it to your project, please follow the steps below:
- Put its source files (XPTabCtrl.cpp and XPTabCtrl.h) into the proper project folder and add their file names to your Visual Studio project.
- Include its header to the appropriate header file—usually a dialog class header where the
CXPTabCtrl
class is used. - You should replace
CTabCtrl
withCXPTabCtrl
everywhere in the project where you want new XP Themes tab behaviour.CXPTabCtrl m_tabCtrl
- If
CXPTabCtrl
has images, the appropriate bitmapIDB_TABIMAGES
(or other with correct tab images) should be included as resource bitmap. It is also necessary to call theInitImageList(IDB_TABIMAGES)
function, fromOnInitDialog
or other appropriate initialising place:
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"
m_tabCtrl.InitImageList(IDB_TABIMAGES); // only necessary
// to call if tabs
// have images
Although the tab control orientation is usually set in the resource editor or in the Tab’s Create
function, CXPTabCtrl
orientation can be changed any time while application is running.
4. Other Techniques
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:
- How to mirror a bitmap image vertically quickly and simply by using only two Windows calls,
GetDIBits
andSetDIBits
. This works in any colour resolution. - How to rotate a rectangular bitmap image fast and in any colour resolution.
- How to use an inline assembler for lengthy repetitive processing; in this case, rotating bitmap image pixels. If the image has large dimensions (large tab control body), C-style coding could take considerable more time than an assembler version.
- How to use XP Themes functions in application, which can run on earlier operating systems.
- How to enable XP Themes a dialog texture background.
- How to make an application XP Themes-aware by simply copying XP manifest, resource “24”, ID “1” from one application resource to another.
- How to use tab ToolTips.
5. Testing Conditions
- 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 and Windows NT 4.0 (CXPTabCtr does not have effect)
- Other Windows systems could have possible problems (?)
- The sample has been tested on these colour resolutions: 8-bit, 16-bit, 24-bit, and 32-bit colours
- The sample has not been tested on multiline (stacked) tabs; could be problems (?)
6. Feedback
Please post your questions, suggestions, and bug reports only to the forum below.