?
Solved

2 Questions about tab control

Posted on 2002-04-28
8
Medium Priority
?
398 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
[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
  • 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
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.

 
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 200 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

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