MFC- Tab Control - Problem implementing dynamic tabs.

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.
LVL 1
ArrummzenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArrummzenAuthor Commented:
oopps, I didnt meen to post to, Is there anyway I can get this one deleated? If not just dont relpy to this one.
0
aparyaniCommented:
Do not try to store CWnd objects globally.

Try getting the tab control locally such as

CTabCtrl* pTabCtrl;
pTabCtrl;= (CTabCtrl*) GetDlgItem(IDC_EDIT1);

Then use your code using pTabCtrl;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.