?
Solved

MFC- Tab Control - Problem implementing dynamic tabs.

Posted on 2003-02-22
6
Medium Priority
?
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 8001980
try

         if (strcmp(CurTab.pszText, name)==0)
         {
              SubMen.DeleteItem ( cout );
              return 1; // 1 == succses
         }
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8003965
I got
"Unhandled exception at 0x004f0950 in E-Ref.exe: 0xC0000005: Access violation reading location 0xcccccccc."
I am not sure what this means but I do not think its good...
Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8004123
IT appears to me that the SubMen.GetItem ( cout , &CurTab ); call is not working correctly. I don't know why its not working however. All I know is that when I call GetItem on the first 3 tabs I am not getting a single valid string pointer returned when there should be a valid string.
Thank you for your time,
Arrummzen
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 9

Expert Comment

by:Priyesh
ID: 8004882
try this.

int CappDlg::DeleateTabByName (char* name)
{    
    char szTabText[256] ;

    TCITEM CurTab;
    CurTab.mask = TCIF_TEXT;
    CurTab.pszText = szTabText ;
    CurTab.cchTextMax = 256 ;

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

    int cout;
    for ( cout = 0 ; cout <= num ; cout++)
    {
         BOOL fail = m_Tab1.GetItem ( cout , &CurTab );
         if ( fail = FALSE )
         {
              AfxMessageBox ("ERROR");
         }
         if (strcmp(CurTab.pszText,name) == 0)
         {
              m_Tab1.DeleteItem ( cout );
         }
    }
}
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 2000 total points
ID: 8004903
"pszText" should be the address of a buffer to recieve text and "cchTextMax" should be the length of the buffer pointed by pszText. So when you call GetItem without initializing these values the function will not work properly.
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8006069
Thanks, your code did not work, but I used to to figure out whats wrong with mine.
Thank you for your time,
Arrummzen
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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