I have Tabctrl in a dialog.I want to set its background colour for each tab .I tried ON_WM_DRAWITEM but the control never comes in OnDrawItem().Can you help?
#define RED RGB(255,0,0)
#define YELLOW RGB(255,255,0)
#define MAGENTA RGB(255,0,255)
#define WHITE RGB(255,255,255)
#define BLUE RGB(0,0,255)
void CVMListDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
CDialog::OnDrawItem(nIDCtl, lpdis);
char szTabText[100];
RECT rect;
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
CTabCtrl *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB_VM);
if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
// which tab?
switch (lpdis->itemID)
{
case 0:
cbr = &m_brRed;
bkColor = RED;
break;
case 1:
cbr = &m_brYellow;
bkColor = YELLOW;
break;
case 2:
cbr = &m_brMagenta;
bkColor = MAGENTA;
break;
case 3:
cbr = &m_brWhite;
bkColor = WHITE;
break;
case 4:
cbr = &m_brBlue;
bkColor = BLUE;
break;
}
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;
pTabCtrl->GetItem(lpdis->itemID, &tci);
CDC *dc = CDC::FromHandle(lpdis->hDC);
dc->FillRect(&lpdis->rcItem, cbr);
dc->SetBkColor(bkColor);
TextOut(lpdis->hDC,
lpdis->rcItem.left,
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));
}
}