CTabCtrl question!

I got MFC CTab control in the dialog. It is inserted using resource editor, and bunch of other controls are pasted onto it.

In the OnInitDialog() function tab is extended like this:


Answer this question

CTabCtrl question!

  • zoulasc

    It sure makes the code neater!

    But now I got a new problem. If you can help, please try:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=256727&SiteID=1&mode=1

    Thanx!


  • Neil K.

    Ok, and when I try using TCITEM structure, problem of disappearing controls is not solved:


    void CMFC02Dlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)

    {

    CString tmpString;

    *pResult = 0;

    int selectedTab = Tab.GetCurSel();

    TCITEM newItem;

    if (selectedTab == numberOfTabs)

    {

    tmpString.Format("Scenario %d", numberOfTabs+1);

    newItem.mask = LVIF_TEXT;

    newItem.dwState = TCIF_STATE;

    newItem.pszText = (LPSTR)&tmpString;

    newItem.iImage = -1;

    Tab.SetItem(numberOfTabs, &newItem);

    Tab.InsertItem(numberOfTabs+1, "(new scenario)");

    numberOfTabs++;

    }

    }



  • Elizabeth Maher MS

    Ok, I fixed the defect - I just inserted this->RedrawWindow() and came back to deleting/inserting items which is MUCH easier for me, and all is fine now.

     

    Thanx anyway!


  • awani

    Yes you need to use TCITEM struct. And this is faster and better than your code.



  • rjherbein

    Well I tried Tab.SetItem(number, "Title") with "number" containing a number of last item, but it didn't work, it just says:

    cannot convert parameter 2 from 'CString *__w64 ' to 'TCITEMA *'

    In msdn, under "CTabCtrl" there is no "events" link and also I searched keyword "OnTcnSelchange" with no result so I thought it is not documented.

    Thanx for the help with msdn!


  • Roman S. Golubin

    You can obmit the delete. This adds the new entry in front of the last one:

    if (selectedTab == numberOfTabs)

    {

    tmpString.Format("Scenario %d", numberOfTabs+1);

    Tab.InsertItem(numberOfTabs, tmpString); // (adding)

    numberOfTabs++;

    }


  • Aaron Winters

    This notification is well documented:
    http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/tab/notifications/tcn_selchange.asp frame=true

    I directly see no problem.But why do you delete the last item. Just use SetItem and change the text of the last item and add a new one.



  • ScorpDaddy

    Should I use TCITEM structure instead of string If so, I guess it is more complicated way, isn't it
  • CTabCtrl question!