Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

specify background color for CTabCtrl

1,191 views
Skip to first unread message

Joerg Mauz

unread,
Jun 7, 2004, 1:39:13 PM6/7/04
to
hi all,
 
 
i really got frustrated when trying to get my tabcontrols colored...
here's the situation:
 
 
+--------------------------------------------------------------+
|  TAB A  \  TAB B \  TAB C \ #################################|
+--------------------------------------------------------------+
|                                                              |
|                                                              |
|          bla bla                                             |
|                                                              |
|                                                              |
|                                                              |
+--------------------------------------------------------------+
 
i got my propertysheet and my propertypage colored in the way
i wanted, but the tab controller refuses to do so...
those charakters marked as # in the illustration above are still
colored in standard windows grey :-((
 
i could find a OnCtlColor function for CTabCtrl.. that's the way
i got the other widgets colored..
are there any ideas on how to get this part of my app 'dressed'
the way i like ?
 
thanks in advance !
 
cheers
 
  joerg

Jeff Partch

unread,
Jun 7, 2004, 2:01:13 PM6/7/04
to
"Joerg Mauz" <Joerg_Mauz...@abs.org> wrote in message
news:40c4a8f3$0$271$4d4e...@read.news.de.uu.net...

+--------------------------------------------------------------+
| TAB A \ TAB B \ TAB C \ #################################|
+--------------------------------------------------------------+

i got my propertysheet and my propertypage colored in the way


i wanted, but the tab controller refuses to do so...
those charakters marked as # in the illustration above are still
colored in standard windows grey :-((

i could find a OnCtlColor function for CTabCtrl.. that's the way
i got the other widgets colored..
are there any ideas on how to get this part of my app 'dressed'
the way i like ?

It's been a while, but my recollection is that you need to handle
WM_ERASEBKGND in a subclass.
--
Jeff Partch [VC++ MVP]


Relvinian

unread,
Jun 7, 2004, 2:03:29 PM6/7/04
to
Taking a stab because I am not at home to experiment but it sounds like you need to handle the WM_NCPAINT message and draw the background color of the non-client area of your tab control to change the color of the area where you have mentioned.
 
Relv
hi all,

Patrick Brunmayr

unread,
Jun 8, 2004, 2:20:34 AM6/8/04
to

"Relvinian" <m...@msn.com> wrote in message
news:zdednQbcoNh...@comcast.com...

Relv

thanks in advance !

cheers

joerg

Hi

You have to set the TCS_OWNERDRAWFIXED style to the tab control and
overwrite DrawItem

Example


BOOL CMyTabControl::OnEraseBkgnd(CDC* pDC)
{
CRect rcClient;
GetClientRect(&rcClient);
pDC->FillSolidRect(rcClient, m_bkgColor);
// Bkg Color for your Tab Control
return TRUE;
}

void CMyTabControl::DrawItem(LPDRAWITEMSTRUCT lpDIS) // Drawing one
Tab
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
CRect rc(lpDIS->rcItem);
TCHAR szTabText[255];
TC_ITEM tci;
tci.cchTextMax = sizeof(szTabText)-1;
tci.pszText = szTabText;
tci.mask = TCIF_TEXT;
GetItem(lpDIS->itemID, &tci);
pDC->SetBkColor(m_bkgColor);
pDC->FillSolidRect(&lpDIS->rcItem, m_bkgColor);


if (lpDIS->itemState & ODS_SELECTED)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->DrawText(szTabText, &lpDIS->rcItem , DT_CENTER | DT_VCENTER |
DT_SINGLELINE);
}
else
{
pDC->SetTextColor(RGB(0,0,0));
pDC->DrawText(szTabText, &lpDIS->rcItem , DT_CENTER | DT_BOTTOM |
DT_SINGLELINE);
}
}

Hope this wil help you

Pat


Joerg Mauz

unread,
Jun 8, 2004, 9:49:02 AM6/8/04
to
thanks for your information..

do i also have to overload the CPropertySheet Class
when using its GetTabControl() function ?

'cause at the moment GetTabControl() returns me CTabCtrl Objects
an not the expected CMyTabControl objects :-((

thanks in advance

cheers

joerg

"Patrick Brunmayr" <patrick....@gascad.at> schrieb im Newsbeitrag
news:#74vRBST...@TK2MSFTNGP12.phx.gbl...

Joerg Mauz

unread,
Jun 8, 2004, 2:20:39 PM6/8/04
to
hi all,

got the tabs and there back working, but the textcolor changed also
and the tabs' titels can't be read.. it seems they're deleted when
colorize the background..
any ideas of how to get the tabs' title colored ?

TIA !!

cheers
joerg


0 new messages