Solved

2 Questions about tab control

Posted on 2002-04-28
8
331 Views
Last Modified: 2013-11-20
i have a tabbed view application.
in the begining of the program i'd like to have 9 basic tabs and to allow in the future to add more tabs.
so in OnNewDocument() of my document class i return FALSE and i would like somewhere in the application before it started to open 9 tabs with different titles.
how can i do it?

btw, all my 9 tabs are form views which inheriut from the tab view.


0
Comment
Question by:sedgwick
  • 4
  • 4
8 Comments
 
LVL 42

Author Comment

by:sedgwick
ID: 6976443
Q2:  i have a properties dialog in which une can change the style of the tab control, for example from tab to buttons or from top to bottom.
the problem is that it never update the control correctly.

in the dialog i have check boxes which getting updated when the dialog is open.

i'm using static member from type DWORD which holds the tab style.

here's some code:
class CPropertiesDialog : public CDialog
{
// Construction
public:
     CPropertiesDialog(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
     //{{AFX_DATA(CPreferencesDialog)
     enum { IDD = IDD_PROPERTIES_DIALOG };
     BOOL     m_chkButtonsTabs;
     BOOL     m_chkMultiline;
     BOOL     m_chkScrollOpposite;
     BOOL     m_chkTabsTop;
     BOOL     m_chkRightJustify;
     BOOL     m_chkFixedWidth;
     //}}AFX_DATA

     static DWORD GetTabsStyle(){return m_dwTabsStyle;}
protected:
     static DWORD m_dwTabsStyle;
. . .

before exit the dialog i'm updating the data member accordingly:

void CPreferencesDialog::OnDestroy()
{
     m_chkButtonsTabs     ? m_dwTabsStyle |= TCS_BUTTONS : m_dwTabsStyle &= ~TCS_BUTTONS;
     m_chkFixedWidth          ? m_dwTabsStyle     |= TCS_FIXEDWIDTH    : m_dwTabsStyle &= ~TCS_FIXEDWIDTH   ;
     m_chkMultiline          ? m_dwTabsStyle |= TCS_MULTILINE    : m_dwTabsStyle &= ~TCS_MULTILINE   ;
     m_chkRightJustify     ? m_dwTabsStyle |= TCS_RIGHTJUSTIFY    : m_dwTabsStyle &= ~TCS_RIGHTJUSTIFY   ;
     m_chkScrollOpposite ? m_dwTabsStyle |= TCS_SCROLLOPPOSITE : m_dwTabsStyle &= ~TCS_SCROLLOPPOSITE;
     !m_chkTabsTop          ? m_dwTabsStyle |= TCS_BOTTOM : m_dwTabsStyle &= ~TCS_BOTTOM;

     CDialog::OnDestroy();
}


void CMainFrame::OnViewProperties()
{
     CPropertiesDialog dlg;
     if(dlg.DoModal() == IDOK)
          m_MTIClientWnd.GetTabCtrl()->ModifyStyle(DEFAULT_TABS_STYLE_PARAMS, CPropertiesDialog::GetTabsStyle());
}

do u detect something wrong with the code?

maybe in the initialization?

0
 
LVL 42

Author Comment

by:sedgwick
ID: 6976451
Q2:  i have a properties dialog in which une can change the style of the tab control, for example from tab to buttons or from top to bottom.
the problem is that it never update the control correctly.

in the dialog i have check boxes which getting updated when the dialog is open.

i'm using static member from type DWORD which holds the tab style.

here's some code:
class CPropertiesDialog : public CDialog
{
// Construction
public:
     CPropertiesDialog(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
     //{{AFX_DATA(CPreferencesDialog)
     enum { IDD = IDD_PROPERTIES_DIALOG };
     BOOL     m_chkButtonsTabs;
     BOOL     m_chkMultiline;
     BOOL     m_chkScrollOpposite;
     BOOL     m_chkTabsTop;
     BOOL     m_chkRightJustify;
     BOOL     m_chkFixedWidth;
     //}}AFX_DATA

     static DWORD GetTabsStyle(){return m_dwTabsStyle;}
protected:
     static DWORD m_dwTabsStyle;
. . .

before exit the dialog i'm updating the data member accordingly:

void CPreferencesDialog::OnDestroy()
{
     m_chkButtonsTabs     ? m_dwTabsStyle |= TCS_BUTTONS : m_dwTabsStyle &= ~TCS_BUTTONS;
     m_chkFixedWidth          ? m_dwTabsStyle     |= TCS_FIXEDWIDTH    : m_dwTabsStyle &= ~TCS_FIXEDWIDTH   ;
     m_chkMultiline          ? m_dwTabsStyle |= TCS_MULTILINE    : m_dwTabsStyle &= ~TCS_MULTILINE   ;
     m_chkRightJustify     ? m_dwTabsStyle |= TCS_RIGHTJUSTIFY    : m_dwTabsStyle &= ~TCS_RIGHTJUSTIFY   ;
     m_chkScrollOpposite ? m_dwTabsStyle |= TCS_SCROLLOPPOSITE : m_dwTabsStyle &= ~TCS_SCROLLOPPOSITE;
     !m_chkTabsTop          ? m_dwTabsStyle |= TCS_BOTTOM : m_dwTabsStyle &= ~TCS_BOTTOM;

     CDialog::OnDestroy();
}


void CMainFrame::OnViewProperties()
{
     CPropertiesDialog dlg;
     if(dlg.DoModal() == IDOK)
          m_MTIClientWnd.GetTabCtrl()->ModifyStyle(DEFAULT_TABS_STYLE_PARAMS, CPropertiesDialog::GetTabsStyle());
}

do u detect something wrong with the code?

maybe in the initialization?

0
 
LVL 37

Expert Comment

by:zzynx
ID: 6976498
About your first question: this may help:

CTabCtrl *pTabCtrl = GetTabControl();
int iNrTabs = pTabCtrl->GetItemCount();
for (int i=1; i<iNrTabs; i++)
{
  TCITEM tcItem;
  CString strText;

  tcItem.mask = TCIF_TEXT;
  tcItem.cchTextMax = 0;
  tcItem.pszText = NULL;
  //  Set the new text
  strText = "What&ever you want";
  tcItem.pszText = strText.GetBuffer(256);
  pTabCtrl->SetItem(i, &tcItem);
}

Success
0
 
LVL 42

Author Comment

by:sedgwick
ID: 7005069
zzynx: where can i put those code lines?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 37

Expert Comment

by:zzynx
ID: 7005300
Hi sedgwick,
I put it in the OnInitDialog() of the class you derived from CPropertySheet.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 7005323
Hi sedgwick,

about your 2nd Q: not all styles can be changed after the tab control is created. In the MSDN help for tab control styles I read:

The following styles can be modified after the control is created:

TCS_BOTTOM
TCS_BUTTONS
TCS_FIXEDWIDTH
TCS_FLATBUTTONS
TCS_FORCEICONLEFT
TCS_FORCELABELLEFT
TCS_MULTILINE
TCS_OWNERDRAWFIXED
TCS_RAGGEDRIGHT
TCS_RIGHT
TCS_VERTICAL

So, some of the styles you're trying to change will certainly not work.
0
 
LVL 42

Author Comment

by:sedgwick
ID: 7036345
do u know how to add icons to tab control maybe?
0
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 7038857
I know two possibilities:

1) The code should be placed in the constructor of CMyPropertySheet.

CMyPropertySheet is derived from CPropertySheet.
The object m_Page1 is defined in the header file:

CMyPage m_Page1;

CMyPage is derived from CPropertyPage.
CMyPropertySheet::CMyPropertySheet(CWnd* pWndParent)
: CPropertySheet(IDS_PROPSHT_CAPTION, pWndParent)
{
  m_Page1.m_psp.dwFlags |= PSP_USEHICON ;
  m_Page1.m_psp.hIcon = AfxGetApp() -> LoadIcon(IDI_SMALL_ICON);

  AddPage(&m_Page1);
}

2) Use an imagelist

Add this again in the OnInitDialog() handler of your class derived from CPropertySheet:

CTabCtrl* pTab = GetTabControl();
VERIFY(m_TabImageList.Create(IDB_TABICONS, 16, 0, RGB(255, 0, 0)));
pTab->SetImageList(&m_TabImageList);

TCITEM tcItem;
ZeroMemory(&tcItem, sizeof(TCITEM));

tcItem.mask = TCIF_IMAGE;
int nTabs = pTab->GetItemCount();
for (int i = 0; i < nTabs; i++)
{
  tcItem.iImage = i;
  pTab->SetItem( i, &tcItem );
}

Success
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now