Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Owner Draw CTabCtrl

Posted on 2004-03-25
14
Medium Priority
?
5,072 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 45

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:wilsonian
ID: 10700978
No difference.
0
 

Author Comment

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

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
 
LVL 45

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 45

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 45

Accepted Solution

by:
AndyAinscow earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 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