Solved

Owner Draw CTabCtrl

Posted on 2004-03-25
14
5,005 Views
Last Modified: 2013-11-20
Hi there,

I'm trying to use an owner draw CTabCtrl as explained here:

http://www.codeguru.com/Cpp/controls/controls/tabcontrols/article.php/c2237

So I've included the source files given in my project. Then in my subclass of CPropertySheet I have in the header file:
CTabCtrlEx m_tabCtrl;

And in the cpp file in OnInitDialog:
m_tabCtrl.SubclassWindow(GetTabControl()->m_hWnd);

However the DrawItem in CTabCtrlEx never gets called. What have I missed?

Thank you.

0
Comment
Question by:wilsonian
  • 8
  • 5
14 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 10682743
Make sure you have specified the TCS_OWNERDRAWFIXED style for the tab control.
0
 

Author Comment

by:wilsonian
ID: 10682796
From TabCtrlEx.cpp:

int CTabCtrlEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CTabCtrl::OnCreate(lpCreateStruct) == -1) return -1;
      ModifyStyle(0, TCS_OWNERDRAWFIXED | TCS_FIXEDWIDTH);
      
      return 0;
}
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10684927
try this in your OnInit of the property sheet

      // get HWND of tab control and subclass it
      HWND hWndTab = (HWND)SendMessage(PSM_GETTABCONTROL);
      m_tabCtrl.SubclassDlgItem(::GetDlgCtrlID(hWndTab), this);
0
 

Author Comment

by:wilsonian
ID: 10700978
No difference.
0
 

Author Comment

by:wilsonian
ID: 10700979
No difference.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10701704
You need to do the ModifyStyle in the SubclassDlgItem function of your customised TabControl.  (Does your onCreate ever get called?)
0
 

Author Comment

by:wilsonian
ID: 10701785
No, but this does:

void CTabCtrlEx::PreSubclassWindow()
{      
      CTabCtrl::PreSubclassWindow();
      ModifyStyle(0, TCS_OWNERDRAWFIXED | TCS_FIXEDWIDTH);
}

Adding this makes no difference:

BOOL CTabCtrlEx::SubclassDlgItem(UINT nID, CWnd* pParent)
 {
    if (!CTabCtrl::SubclassDlgItem(nID, pParent))
       return FALSE;
    ModifyStyle(0,TCS_OWNERDRAWFIXED | TCS_FIXEDWIDTH);
      return TRUE;
}

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10701986
Interesting it doesn't work for you.
The two code snippets I posted are from functional owner draw tab (used on a property sheet).
0
 

Author Comment

by:wilsonian
ID: 10702670
Yes, well CTabCtrlEx I'm pretty sure works, it's from CodeGuru.  I'm thinking I'm using it in my PropertySheet class wrong, but I can't work out how.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10703115
No, but this does:
void CTabCtrlEx::PreSubclassWindow()

and later:
I'm thinking I'm using it in my PropertySheet class wrong, but I can't work out how.




I'm puzzled now.  Does it work or does it still not call the DrawItem function?  Have you got a TRACE or a breakpoint in your DrawItem to check if it is being called.  (It might be but the drawing is not getting done for some reason.  <Find the problem then solve it.  Don't assume the problem is here as it might not be.>).
0
 

Author Comment

by:wilsonian
ID: 10707522
I have a breakpoint at the start of DrawItem and it's never getting there.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 10711644
I have the following
//////////////////
// Subclass the tab control: also make owner-draw
//
bool COwnerDrawTab::SubclassDlgItem(UINT nID, CWnd* pParent)
{
      if (!CTabCtrl::SubclassDlgItem(nID, pParent))
            return false;

      ModifyStyle(0, TCS_OWNERDRAWFIXED);


and
in PropSheet header
      COwnerDrawTab m_OwnerDrawTab;


BOOL CXXPropertySheet::OnInitDialog()
{
      CPropertySheet::OnInitDialog();
      
      // get HWND of tab control and subclass it
      HWND hWndTab = (HWND)SendMessage(PSM_GETTABCONTROL);
      m_OwnerDrawTab.SubclassDlgItem(::GetDlgCtrlID(hWndTab), this);


The above code does work.  Can you try it as posted in your app.
0
 

Author Comment

by:wilsonian
ID: 10720321
Aha!  I've found the problem.  I had a function CXXPropertyPage::OnDrawItem, which was stopping the CTabCtrlEx::DrawItem from firing. This function has happily become redundant since I put it in there, so I can just get rid of it.
0
 

Author Comment

by:wilsonian
ID: 11028655
Hi, sorry about keeping this question and the one about icon view list controls open so long.  I never know what to do in these situations where an expert is very helpful in the sense of expending effort to assist me, but yet doesn't help me arrive at a solution.  But I'll bite the bullet and give you the points anyway, unless you have some objection
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now