Hi all:
I used the MS method to change the background color of tab control in MFC.
http://support.microsoft.com/default.aspx?scid=kb;en-us;179909[
^]
#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 CMFCTabCtrlDlg::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_TAB1);
if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
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));
}
}
I used the wizard to produce the OnDrawItem( ).
I guessed the m_brRed, m_brYellow and so on is the instance for each Tab.
in my code, I used
CPage1 m_page1;
CPage2 m_page2;
But I can't build it.....
I thought maybe I can't build it because I can't understand for this sentence in the article:
First bring up the properties for the tab control in the Resource Editor and select the Styles tab. Select the "Owner draw fixed" check box and save your work.
If you are dynamically creating the Tab control during the dialog box's initialization with CreateWindow() or CreateWindowEx() be sure to include the TCS_OWNERDRAWFIXED bit in the dwStyle parameter.
I have select the "Owner draw fixed" check box, But I'm confused for the second sentence.
How can I "include the TCS_OWNERDRAWFIXED bit in the dwStyle parameter" ?
Thank you, everyone,
best regard.