Microsoft KB Archive/206626

= How to change the text color of the selected property sheet tab in Visual C++ =

Article ID: 206626

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li> Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q206626

<div class="notice_section">

NOTE: Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="summary_section">

SUMMARY
To change the color of text on the selected tab of a property sheet, you need to subclass the tab control associated with the property sheet and make it owner drawn.

Override the DrawItem method of your class derived from CTabCtrl and change the color of text before displaying it.

<div class="moreinformation_section">

MORE INFORMATION
<ol>  Create a new class called CMyTabCtrl deriving from CTabCtrl. Override the DrawItem method for CTabCtrl. Because ClassWizard does not show this method, this method needs to be added manually. The sample code below shows how to change the color of the text of the selected tab:

void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS) {    TC_ITEM tci; CDC* pDC = CDC::FromHandle(lpDIS->hDC); CRect rect(lpDIS->rcItem); char szTabText[256]; memset(szTabText,'\0',sizeof(szTabText)); tci.mask = TCIF_TEXT; tci.pszText = szTabText; tci.cchTextMax = sizeof(szTabText) -1; GetItem(lpDIS->itemID, &tci); if (lpDIS->itemAction & ODA_DRAWENTIRE) {        pDC->TextOut(rect.left+5, rect.top+5, tci.pszText); }    if ((lpDIS->itemState & ODS_SELECTED) &&          (lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE))) {        //Make the color of text of the selected tab to be BLUE. pDC->SetTextColor(RGB(0,0,255)); pDC->TextOut(rect.left+5, rect.top+5, tci.pszText); } }                       </li>  Create a new class, CMyPropertySheet, derived from CPropertySheet and add a member variable m_myTabCtrl of type CMyTabCtrl.

Add a handler for WM_INITDIALOG message. After the call to the base class OnInitDialog, add the code as shown below to subclass the tab control and make it an owner-drawn control:

BOOL CMyPropertySheet::OnInitDialog {  BOOL bResult = CPropertySheet::OnInitDialog;

/* Subclass the tab control. */   m_myTabCtrl.SubclassWindow(GetTabControl->m_hWnd);

/* Make it owner drawn. */   m_myTabCtrl.ModifyStyle(0,TCS_OWNERDRAWFIXED);

return bResult; }

</li></ol>

Now, use CMyPropertySheet instead of CPropertySheet in your application.

<div class="references_section">