troubleshooting Question

MFC- Tab Control - Problem implementing dynamic tabs.

Avatar of Arrummzen
Arrummzen asked on
System Programming
2 Comments1 Solution573 ViewsLast Modified:
I want to be able to add tabs dyanmicly to the tab control during program operation, I will not know witch tabs or in what order they will need to be added.
I tried solving this problem by assigning an index to each tab so I could add and remove them by useing there index however If I have tabs 1,2 and 3 on a form and 1 is removed then 2 becomes 1 and 3 becomes 2. This messess things up.
To solve the probelm I want to identify the tabs by there names. So I added a "add tab by name" and "remove tab by name" meathod.

[code]
int CappDlg::DeleateTabByName (char name[])
{
     TCITEM CurTab;
     CurTab.mask = TCIF_TEXT;

     int num = SubMen.GetItemCount();
     num++;

     int cout;
     for ( cout = 0 ; cout <= num ; cout++)
     {
          BOOL fail = SubMen.GetItem ( cout , &CurTab );
          if ( fail = FALSE )
          {
               AfxMessageBox ("ERROR");
          }
          if ( CurTab.pszText == name)
          {
               SubMen.DeleteItem ( cout );
               return 1; // 1 == succses
          }
     }

     return 0; // 0 == failure
     return -1; // -1 means not implemented    

}

int CappDlg::addTabByName (char name[])
{
     TC_ITEM TabCtrlItem;
     TabCtrlItem.mask = TCIF_TEXT;
     TabCtrlItem.pszText = name;
     SubMen.InsertItem ( 1 , &TabCtrlItem );

     return 1; // 1 == succsess
}
[code/]

The add tab by name function works correcly but the remove tab by name tab does not. Why does the remove tab by name function fail to work?
I tried debuging and I find that CurTab's sting value is bad, it says that the pointer is invalied. I don't see how this could be however becuse the GetItem meathod returns true.
I have no idea why thid does not work but it might have something to do with the invalid string in CurTab.
ASKER CERTIFIED SOLUTION
aparyani

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros