Home > MFC, Windows API > How to make tab control pages transparent while using XP themes?

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

BEGIN_MESSAGE_MAP(CTabPage, CDialog)
     ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

Override OnCtlColor and add following code…

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 )
   {
      case CTLCOLOR_STATIC:
      case CTLCOLOR_DLG:
          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.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: