Solved

Owner Draw CTabCtrl

Posted on 2004-03-25
14
5,024 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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: 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 …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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