How to make tab control pages transparent while using XP themes?

Having trouble with tab control pages’  gray background while using XP themes? Well to solve this problem we need to do some additional housekeeping(AFAIK)…

Add a message map entry for WM_CTLCOLOR

[sourcecode language=’cpp’]BEGIN_MESSAGE_MAP(CTabPage, CDialog)

Override OnCtlColor and add following code…

[sourcecode language=’cpp’]HBRUSH CTabPage::OnCtlColor( CDC* pDC_i, CWnd* pWnd_i, UINT uCntrlType_i )

// First do default always
HBRUSH hBrTemp = CDialog::OnCtlColor( pDC_i, pWnd_i, uCntrlType_i );

// If we have a static control or a dialog control we should return our brush
// with the DC having a transparent background
switch( uCntrlType_i )
pDC_i->SetBkMode( TRANSPARENT ); // Transparent mode
hBrTemp = GetSysColorBrush( IsAppThemed() ? COLOR_WINDOW : COLOR_BTNFACE ); // Our brush

// Return brush to caller
return hBrTemp;

Note that we don’t need to delete the created brush since we are using a system cached brush. Also it’s good that you create a custom class(something like CTabPage, make this new class derive from CDialog.) and add this code there and then derive all your tab pages from this class instead of CDialog.

Appreciate your comments...