Yogesh
Yogesh

Reputation: 1585

CMFCOutlookBarTabCtrl::SetActiveTab not working

I have added a CMFCOutlookBar control to a dialog. This outlookbar contains some 12 trees.

As per following link https://msdn.microsoft.com/en-us/library/bb983453.aspx we can set active tab (in my case tree control) of our wish.

but it doesn't seems to work.

as per above link this function returns non zero value on success. Indeed it is returning 1 when i used it to set tree of my choice. but visually it's not changed.

can someone help me?

Upvotes: 3

Views: 352

Answers (2)

Tom Carpenter
Tom Carpenter

Reputation: 571

I had the same problem, and you are correct that on load the tab gets set to the last session value - actually it seems to get set several times during the load process - some of them seem to correspond to each time a tab is added, and then the last time it is called seems to be the tab from the previous session.

The solution is to set the value once the window is ready to be shown. This can be done by overriding the OnShowWindow callback on the view which contains the tab bar.

In my case the tab bar is added in a view called MainFrame, which has a member variable CMFCOutlookBarTabCtrl* m_pOutlookBar; which is initialised in the OnCreate callback.

I can then correctly set the tab by overriding OnShowWindow to contain the following:

void MainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
{
    CFrameWndEx::OnShowWindow(bShow, nStatus);

    if ((m_pOutlookBar != NULL) && bShow) {
        //When the tab bar is shown, select the correctview
        for (int tabIdx = 0; tabIdx < m_pOutlookBar->GetTabsNum(); tabIdx++) {
            CString requiredLabel;
            CString thisLabel;
            requiredLabel.LoadString(IDS_OF_TAB); //The ID of the tab wanted
            m_pOutlookBar->GetTabLabel(tabIdx,thisLabel);
            if (requiredLabel.Compare(thisLabel) == 0) {
                //If the tab label matches the one required
                m_pOutlookBar->SetActiveTab(tabIdx); //set it as the active one.
                break; //done.
            }
        }
    }
}

Upvotes: 0

Yogesh
Yogesh

Reputation: 1585

Problem solved. CMFCOutlookBarTabCtrl::SetActiveTab() only works after window has been displayed. I guess this is because CMFCOutlookBar stores it's previous state to registory and reloads on next run. And this overrides changes made by SetActiveTab(), if we use it before displaying of window.

Upvotes: 2

Related Questions