Hello and happy new year, (permissible to say this until Thursday)
I am trying to change the color of tabs in the CTabCtrl class. I am trying to create my own ReskinCTablCtrl so that I can just call it in separate classes and use it easily throughout my program.
Currently, I can change the background color of CTabCtrl, but I cannot change the tab myself.
I used ON_WM_ERASEBKGND()
to paint the background and it worked without problems:
BOOL ReskinCTabCtrl::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);
CBrush myBrush(RGB(51, 51, 51));
BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
pDC->SetBkColor(RGB(51, 51, 51));
pDC->FillRect(&rect, &myBrush);
return bRes;
}
However, I was unsuccessful at changing the tab colors themselves. They are still standard MFC colors. I tried to implement ON_WM_PAINT()
and ON_WM_DRAWITEM()
without any success. I think I can navigate to a specific language using both OnDraw and DrawItem, similar to the second link example that I posted at the end of this question.
void ReskinCTabCtrl::OnPaint() {
...
int nTab = GetItemCount();
int nSel = GetCurSel();
if (!nTab)
return;
while (nTab--)
{
if (nTab != nSel)
{
dis.itemID = nTab;
dis.itemState = 0;
VERIFY(GetItemRect(nTab, &dis.rcItem));
dis.rcItem.bottom -= 2;
DrawItem(&dis);
DrawItemBorder(&dis);
}
}
...
}
I would really appreciate at least some direction to solve this problem, perhaps a few more examples or what methods I should focus on using. I do not need tabs for different colors, maybe there is an easy way to do this?
I tried to follow some examples, such as the following links, but I still could not figure out how to do this.
https://support.microsoft.com/en-us/help/179909/how-to-change-the-background-color-of-a-tab-control
https://www.codeproject.com/Articles/1786/Ownerdraw-Tab-Controls-Borders-and-All