Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MFC- Tab Control - Problem implementing dynamic tabs.

Posted on 2003-02-22
3
Medium Priority
?
544 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:Arrummzen
2 Comments
 
LVL 1

Author Comment

by:Arrummzen
ID: 8001515
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
 

Accepted Solution

by:
aparyani earned 1200 total points
ID: 8030544
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question