CTabCtrl::DrawItem
void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CTabCtrl object.
The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before this member function terminates.
void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CTabCtrl object.
The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before this member function terminates.
Override the OnDrawItem() method for your CDialog derived class using Class
Wizard and add the following code, changing variable names as neccessary. It is
important to note that a pointer to a CDC object from the handle of the DC
passed in via the LPDRAWITEMSTRUCT is required, otherwise only the background of
the text will be the desired color. void CMyDialogDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
// TODO: Add your message handler code here and/or call default
char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush; CTabCtrl *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB1); if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
// To determine which tab to be drawn. I assume you only have two tabs
switch (lpdis->itemID)
{
case 0:
cbr = &m_brRed;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
break; case 1:
cbr = &m_brBlue;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
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));
}
// CDialog::OnDrawItem(nIDCtl, lpdis);
}
{
char szTabText[100];
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
LOGBRUSH m_LogBrush;
if(lpdis->itemID%2)
{
cbr = &m_brRed;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
}
else
{
cbr = &m_brBlue;
cbr->GetLogBrush(&m_LogBrush);
bkColor = m_LogBrush.lbColor;
}
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1; GetItem(lpdis->itemID, &tci);
FillRect(lpdis->hDC,&lpdis->rcItem,*cbr);
::SetBkColor(lpdis->hDC,bkColor);
HICON hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDR_MAINFRAME));
DrawIcon(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,hicon);//DrawIconEx is more useful
DeleteObject(hicon);
TextOut(lpdis->hDC,
lpdis->rcItem.left+32,//leave room for icon width
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));
}
分数全部给你吧,那两个兄弟我另外给吧!
可否留下email,以后好向大哥学习!