0

Using Visual C++ MFC.

I have a dialog page, which contains a tab control object. I've created my own tab control class derived from CTabCtrl, where I created all my tab pages contained in an array, like so:

tabArray[0] = new TabPage;
tabArray[1] = new TabPage;

tabArray[0]->Create(DIALOG, this);
tabArray[1]->Create(DIALOG, this);

In my initial dialog page, I have a bunch of checkboxes. Depending on the state of these checkboxes, I add/remove the tab pages (but not the underlying TabPage classes!).

This is done like so. I keep track of which tabs are enabled/disabled in m_fTabEnabled. The state of the tab is toggled with the checkbox. This is used to determine which tab needs to be inserted.

m_fTabEnabled[iTab] = !m_fTabEnabled[iTab];

DeleteAllItems();

for(int i = 0; i < NUMOFTABS; ++i)
{
    if(m_fTabEnabled[i]) InsertItem(i, m_sTabNames[i]);
}

Using this method, I have an issue that if I have three tabs enabled, and I remove the second tab, that the dialog containing the data from the second tab is displayed on the third tab. For example:

tab 1, label 1, contains: 1
tab 2, label 2, contains: 2
tab 3, label 3, contains: 3

remove tab 2, tab 3 is shifted to tab 2

tab 1, label 1, contains: 1
tab 2, label 3, contains: 2
tab 3 hidden.

This causes a problem when I'm retrieving data from the tabs, because what I filled in tab three is lost to the data that used to be in tab two.

Does anybody have any suggestions on ways to manage this?

captainjim
  • 127
  • 1
  • 1
  • 6
  • You can't disable specific tabs (unless you use homemade ownerdraw method) Try instead setting tab's page number using `(ti.mask = TCIF_PARAM; ti.lParam = (LPARAM)page; tab->SetItem(...)`, then in `OnTabSelChange` use `tab->GetItem` to find the page number for the specific tab. – Barmak Shemirani Oct 15 '18 at 15:43
  • If you use `CTabCtrl` you must implement all the logic of control hiding/showing tab children controls when switching tabs by your own hands. My suggestion is to derive from more modern `CMFCTabCtrl` which does all that annoying part implicitly. – sergiol Oct 23 '18 at 10:43

0 Answers0