Solved

2 Questions about tab control

Posted on 2002-04-28
8
364 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 42

Author Comment

by:sedgwick
ID: 7005069
zzynx: where can i put those code lines?
0
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 42
iSeries FTP Exit Program 8 147
difference between String.subString() and String.subSequence() 6 238
pre4 challenge 19 104
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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