Solved

Owner Draw CTabCtrl

Posted on 2004-03-25
14
5,014 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 107
unable to delete all specified values regedit 38 270
List out all word 7 255
sum28 challenge 31 105
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

12 Experts available now in Live!

Get 1:1 Help Now