Highlight the Active Page of a TabControl

Environment: VC6 SP4

Overview

In an application that sports TabControls with several rows of tabs, it can often be
difficult for the user to distinguish which tab has focus. Therefore, this code will
enable you to easily hilight the text of the active tab (see image above).

Usage

There are only two property page functions to implement (OnSetActive and OnKillActive)


BOOL CMyPage::OnSetActive()
{
CPropertySheet* pParent = (CPropertySheet*)this->GetParent();

if (pParent)
{
if (pParent->GetTabControl())
{
short nActiveItem = pParent->GetPageIndex(this);
pParent->GetTabControl()->HighlightItem(nActiveItem);
}
}

return CPropertyPage::OnSetActive();
}


BOOL CMyPage::OnKillActive()
{
CPropertySheet* pParent = (CPropertySheet*)this->GetParent();
if (pParent)
{
if (pParent->GetTabControl())
{
short nActiveItem = pParent->GetPageIndex(this);
pParent->GetTabControl()->HighlightItem(nActiveItem, FALSE);
}
}

return CPropertyPage::OnKillActive();
}

Downloads

Download demo project – 42 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read