Coloring a CTabCtrl problem

Hi

I have canged the color of my dialog (WM_CTLCOLOR) and the color of the actual tabs (WM_ITEMDRAW), but the problem is the body of the selected tab and also a small area to the right of the tabs is not colored, so I derived a class from a tab ctrl and handled the WM_PAINT, but the problem is the OnPaint, paints over the tabs, can someone tell me what I'm doing wrong

Steven
Dj_Fx8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PriyeshCommented:
You might want to avoid the tab rect in the onpaint.

CTabCtrl::GetItemRect  will give you the rectangle of a tab item, you could find the extends of the tab rectangle using this and the window rect of the tab control.
0
waelothmanCommented:
be sure that you return brush containg color you want in the function WM_CTLCOLOR like
BOOL CTestDlg::OnInitDialog()
{
 m_redbrush.CreateSolidBrush(RGB(255,0,0));    
}
Finally do this on the ID_CTLCOLOR handle:

HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
  HBRUSH hbr;
switch (nCtlColor)
  {
  // process my edit controls by ID.
  case CTLCOLOR_EDIT:

  switch (pWnd->GetDlgCtrlID())
    {    
    case IDC_CONTROLE :         // the id of your controle
     pDC->SetBkColor(RGB(255,0,0));  
      pDC->SetTextColor(RGB(0,254,0));  // change the text color
      hbr = (HBRUSH)  m_redbrush;
      break;  
   default:
      hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
      break;
    }  
    break;
 default:
    hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
  }

  return hbr; }
0
AndyAinscowFreelance programmer / ConsultantCommented:
In your customised class (based on CTabCtrl) make a virtual function DrawItem and do your painting of the tab part including the text there.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Dj_Fx8Author Commented:
Hi

Andy I feel your reply is the right way to go, however I had add a msg handler through the class wizzard for WM_DRAWITEM but this never gets called, I noticed you said "make a virtual function DrawItem" and my OnDrawItem wasn't virtual so I changed it to
virtual void DrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct); but again this never gets called??

Steven
0
williamcampbellCommented:

 have you tried In the OnPaint call dont call the base class OnPaint
0
waelothmanCommented:
i think you don't have to inhirit from the main class just use function
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
0
Dj_Fx8Author Commented:
Hi
Forgive me if I'm missing something here but
William I take it you mean to draw the tabs in the on paint, if so how do I get the DC to draw them on

Waelothman OnCtrlColor does not work for a tab ctrl :-( if only so simple
0
Dj_Fx8Author Commented:
Hi wiliam
I didn't quite say that right, got confused, if I draw the tabs in the on paint I have to handle everything, tab edge, font etc where as in the OnDrawItem I just set the colors

0
williamcampbellCommented:

  I think you will have to draw it yourself, is this a problem for you?
0
AndyAinscowFreelance programmer / ConsultantCommented:
OK - maybe you do not have the tab set as owner draw.  Something like the following should help to make it owner draw and it should then get the DrawItem message.

(I used this in making the active tab text appear with a larger font and different colour - it does work, and I think it is what you are trying to accomplish)

bool COwnerDrawTab::SubclassDlgItem(UINT nID, CWnd* pParent)
{
      if (!CTabCtrl::SubclassDlgItem(nID, pParent))
            return false;

      ModifyStyle(0, TCS_OWNERDRAWFIXED);
0
Dj_Fx8Author Commented:
Hi

Andy
I had it set as owner drawen, I got that prob sorted, I had a handler for draw item in the dialog, but even when it did get called the tabs still wern't drawen, so it's looking like I'm going to have to handle drawing the tabs myself.

William
>>>I think you will have to draw it yourself, is this a problem for you?
:-) more of a bother, although I'll run this by you to see if my thoughts are along the right lines. I can draw each tab by looping of the num of tabs and use GetIitemRect, and GetItem to provide my with the required info, more of a prob is drawing the 3d edge of each tab, If I use DrawEdge or RoundedRect I'm going to get a bottom edge on the tab, so I assume to prevent this I have to use regions to prevent this bottom edge.
Am I on the right wave length, if so I need to do I bit of sudying to figure this all out

Steven
0
Dj_Fx8Author Commented:
Andy
I can get the tabs drawen in different colors and fonts easly enough, the prob is when I use OnPaint to color the background of the tab the tabs dissapear
0
AndyAinscowFreelance programmer / ConsultantCommented:
Don't use the OnPaint to paint the tabs if you are doing an owner draw. In your customised OnPaint put as the first line a return and see if the OwnerDraw approach works for you.  If it does forget customising the OnPaint event.
(The OnPaint default behaviour should be calling the DrawItem)
0
AndyAinscowFreelance programmer / ConsultantCommented:
I have a web site www.ainscow.ch  Have a look at the example 3 on that.  That has some screen shots of how this customised tab control looks like.
0
Dj_Fx8Author Commented:
>>>>Don't use the OnPaint to paint the tabs
I'm trying to use the OnPaint to color the page part (under the tab(s))

I'll have a look at your site now
0
Dj_Fx8Author Commented:
Hi I had a look at your example, I can achive a similar tabctrl, but I want mine to
1. have colored tabs (this I can do in DrawItem)
2. color page part (was trying to do in OnPaint)
3. color the area to the right of the tabs
0
AndyAinscowFreelance programmer / ConsultantCommented:
I think I understand now.  You want the whole width of the page up to the top of the tabs drawn.

The following doesn't work quite correctly - is this sort of what you require?

trap WM_ERASEBACKGROUND message for the tab, no OnPaint handler
BOOL COwnerDrawTab::OnEraseBkgnd(CDC* pDC)
{
       CRect rect;
       GetWindowRect(&rect);
      GetParent()->ScreenToClient(&rect);
       pDC->FillSolidRect(&rect, RGB(255, 0, 0));
      return true;      
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dj_Fx8Author Commented:
I think thats the way I need to go, so it looks like there is no easy way of doing it and through all your answers I've got pointed in the right direction, so I'll close this question soon as I feel it has run its course, and split the points based on effort and directional content. I'm sure I'll have a few more question very soon

Thanks to all for you help

Steven
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.