CMFCOutlookBarTabCtrl :: SetActiveTab not working

I added the CMFCOutlookBar control to the dialog. This search string contains about 12 trees.

According to the following link https://msdn.microsoft.com/en-us/library/bb983453.aspx we can set the active tab (in my tree) of our desire.

but it doesn't work.

as stated above, this function returns nonzero on success. Indeed, it returns 1 when I used it to set the tree of my choice. but visually it hasn't changed.

Can anyone help me?

+3


source to share


2 answers


The problem has been resolved. CMFCOutlookBarTabCtrl :: SetActiveTab () only works after the window has been displayed. I think this is because CMFCOutlookBar saves the previous state in a register and reloads on next startup. And that overrides the changes made by SetActiveTab () if we use it before showing the window.



+2


source


I had the same problem and you pointed out correctly that on load the tab gets the value of the last session - in fact it seems to be somewhat set in the load process - some of them seem to match each contribution, then the last time it is called appears to be a tab from a previous session.

The solution is to set the value as soon as the window is ready to be shown. This can be done by overriding the callback OnShowWindow

in the view that contains the tab bar.

In my case, the tab bar is added in a view under the title MainFrame

, which has a member variable CMFCOutlookBarTabCtrl* m_pOutlookBar;

that is initialized in the callback OnCreate

.



I can then set the tab correctly by overriding OnShowWindow

it 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.
            }
        }
    }
}

      

0


source







All Articles