Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Owner Draw CTabCtrl

Posted on 2004-03-25
14
Medium Priority
?
5,063 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

670 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