Thomas Stockbruegger
asked on
How to create a TabControl 500 Points....please help
How can I add a DialogBox to each Tab Register Tab1, Tab2, Tab3???
I would like to add 3 DialogBoxes.
And later work with each DialogBoxes.
I think I have to work with new add a new class for each Tab.
Please be so kind to help me. I am a beginner in Visual C++....and need some credits.
Thank you. 500 Points
m_tabRegister is a variable from CTabCtrl
....OnInitDialog()
//######################## ########## ########## ########
TCITEM Register;
Register.mask=TCIF_TEXT;
//---- set single Register ------
Register.pszText="Tab 1";
m_tabRegister.InsertItem(0 ,&Register );
Register.pszText="Tab 2";
m_tabRegister.InsertItem(1 ,&Register );
Register.pszText="Tab 3";
m_tabRegister.InsertItem(2 ,&Register );
//------------------------ ---------- -------
m_tabRegister.SetCurSel(0) ;// set first Register
//##################### Register ########################## ###
void CTabControlDlg::OnTcnSelch angeRegist er(NMHDR *pNMHDR, LRESULT *pResult)
{
int nChoose = m_tabRegister.GetCurSel();
switch(nChoose)
{
case 0:
UpdateData(FALSE);
break;
case 1:
UpdateData(FALSE);
break;
case 2:
UpdateData(FALSE);
break;
}
*pResult = 0;
}
//######################## ########## ########## #########
I would like to add 3 DialogBoxes.
And later work with each DialogBoxes.
I think I have to work with new add a new class for each Tab.
Please be so kind to help me. I am a beginner in Visual C++....and need some credits.
Thank you. 500 Points
m_tabRegister is a variable from CTabCtrl
....OnInitDialog()
//########################
TCITEM Register;
Register.mask=TCIF_TEXT;
//---- set single Register ------
Register.pszText="Tab 1";
m_tabRegister.InsertItem(0
Register.pszText="Tab 2";
m_tabRegister.InsertItem(1
Register.pszText="Tab 3";
m_tabRegister.InsertItem(2
//------------------------
m_tabRegister.SetCurSel(0)
//##################### Register ##########################
void CTabControlDlg::OnTcnSelch
{
int nChoose = m_tabRegister.GetCurSel();
switch(nChoose)
{
case 0:
UpdateData(FALSE);
break;
case 1:
UpdateData(FALSE);
break;
case 2:
UpdateData(FALSE);
break;
}
*pResult = 0;
}
//########################
http://www.codeguru.com/cpp/controls/controls/tabcontrols/article.php/c5239/
ASKER
Firstly add the CMyTabCtrl.cpp and CMyTabCtrl.h to your project.
?? add a new class to my TabControl??
what kind of member variable is this: m_tabPages and m_nNumberOfPages
Please let me know, thanks.
?? add a new class to my TabControl??
what kind of member variable is this: m_tabPages and m_nNumberOfPages
Please let me know, thanks.
Download demo project and read it, I hope this can help better than my explanations. Download link is in the end of the article.
If you are new in CodeGuru and similar sites, this is the way to work with them - first try code, then read article, if code is working.
Specifically about your question. Using VC++ Class Wizard, you can add variable of type CTabCtrl to the dialog class. Then add line
#include "CMyTabCtrl.h"
to the dialog h-file, and manually change variable type from CTabCtrl to CMyTabCtrl.
If you are new in CodeGuru and similar sites, this is the way to work with them - first try code, then read article, if code is working.
Specifically about your question. Using VC++ Class Wizard, you can add variable of type CTabCtrl to the dialog class. Then add line
#include "CMyTabCtrl.h"
to the dialog h-file, and manually change variable type from CTabCtrl to CMyTabCtrl.
ASKER
Hi Alex,
yes the program works when I load the project into my Visual Studio C++
I have tried the code in a new project that I wrote.
I can not change CTabCtrl m_myTabCtrl to CMyTabCtrl
I will get an error when I start to compile my program.
How can I do this ?
Everything else would works.
Here is the problem:
Error: RegisterAuswahl() same as Init() do not belong to CTabCtrl
...in Dlg.cpp
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
m_myTabCtrl.InsertItem(0, _T("Tab One"));
m_myTabCtrl.InsertItem(1, _T("Tab Two"));
m_myTabCtrl.InsertItem(2, _T("Tab Three"));
m_myTabCtrl.RegisterAuswah l(); //RegisterAuswahl = Init()
// TODO: Hier zusätzliche Initialisierung einfügen
return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
// TabControl_ClassDlg.h : Headerdatei
//
#pragma once
#include "afxcmn.h"
#include "RegisterKontrolle.h"
// CTabControl_ClassDlg Dialogfeld
class CTabControl_ClassDlg : public CDialog
{
// Konstruktion
public:
CTabControl_ClassDlg(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
enum { IDD = IDD_TABCONTROL_CLASS_DIALO G };
protected:
virtual void DoDataExchange(CDataExchan ge* pDX); // DDX/DDV-Unterstützung
// Implementierung
protected:
HICON m_hIcon;
// Generierte Funktionen für die Meldungstabellen
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CTabCtrl m_myTabCtrl;
};
// RegisterKontrolle.cpp : Implementierungsdatei
//
#include "stdafx.h"
#include "TabControl_Class.h"
#include "RegisterKontrolle.h"
#include ".\registerkontrolle.h"
#include "TabOne.h"
#include "TabTwo.h"
#include "TabThree.h"
// RegisterKontrolle
IMPLEMENT_DYNAMIC(Register Kontrolle, CTabCtrl)
RegisterKontrolle::Registe rKontrolle ()
{
m_tabPages[0]=new CTabOne;
m_tabPages[1]=new CTabTwo;
m_tabPages[2]=new CTabThree;
m_nNumberOfPages=3;
}
RegisterKontrolle::~Regist erKontroll e()
{
//------------------------ ---------- ---------- ------
for(int nCount=0; nCount<m_nNumberOfPages; nCount++)
{
delete m_tabPages[nCount];
}
//------------------------ ---------- ---------- ------
}
BEGIN_MESSAGE_MAP(Register Kontrolle, CTabCtrl)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// RegisterKontrolle-Meldungs handler
//######################## ########## ########## #####
void RegisterKontrolle::Registe rAuswahl()
{
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_ DIALOG1, this);
m_tabPages[1]->Create(IDD_ DIALOG2, this);
m_tabPages[2]->Create(IDD_ DIALOG3, this);
m_tabPages[0]->ShowWindow( SW_SHOW);
m_tabPages[1]->ShowWindow( SW_HIDE);
m_tabPages[2]->ShowWindow( SW_HIDE);
RegisterAufbau();// Funktion aufrufen
}
//######################## ########## ########## ########## ########## ###
void RegisterKontrolle::Registe rAufbau()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect .left-1;
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPo s(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
{
m_tabPages[nCount]->SetWin dowPos(&wn dTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
}
//######################## ########## ########## ########## ########## ###
void RegisterKontrolle::OnLButt onDown(UIN T nFlags, CPoint point)
{
// TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein, und/oder benutzen Sie den Standard.
CTabCtrl::OnLButtonDown(nF lags, point);
if(m_tabCurrent != GetCurFocus())
{
m_tabPages[m_tabCurrent]-> ShowWindow (SW_HIDE);
m_tabCurrent=GetCurFocus() ;
m_tabPages[m_tabCurrent]-> ShowWindow (SW_SHOW);
m_tabPages[m_tabCurrent]-> SetFocus() ;
}
}
yes the program works when I load the project into my Visual Studio C++
I have tried the code in a new project that I wrote.
I can not change CTabCtrl m_myTabCtrl to CMyTabCtrl
I will get an error when I start to compile my program.
How can I do this ?
Everything else would works.
Here is the problem:
Error: RegisterAuswahl() same as Init() do not belong to CTabCtrl
...in Dlg.cpp
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
m_myTabCtrl.InsertItem(0, _T("Tab One"));
m_myTabCtrl.InsertItem(1, _T("Tab Two"));
m_myTabCtrl.InsertItem(2, _T("Tab Three"));
m_myTabCtrl.RegisterAuswah
// TODO: Hier zusätzliche Initialisierung einfügen
return TRUE; // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}
// TabControl_ClassDlg.h : Headerdatei
//
#pragma once
#include "afxcmn.h"
#include "RegisterKontrolle.h"
// CTabControl_ClassDlg Dialogfeld
class CTabControl_ClassDlg : public CDialog
{
// Konstruktion
public:
CTabControl_ClassDlg(CWnd*
// Dialogfelddaten
enum { IDD = IDD_TABCONTROL_CLASS_DIALO
protected:
virtual void DoDataExchange(CDataExchan
// Implementierung
protected:
HICON m_hIcon;
// Generierte Funktionen für die Meldungstabellen
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CTabCtrl m_myTabCtrl;
};
// RegisterKontrolle.cpp : Implementierungsdatei
//
#include "stdafx.h"
#include "TabControl_Class.h"
#include "RegisterKontrolle.h"
#include ".\registerkontrolle.h"
#include "TabOne.h"
#include "TabTwo.h"
#include "TabThree.h"
// RegisterKontrolle
IMPLEMENT_DYNAMIC(Register
RegisterKontrolle::Registe
{
m_tabPages[0]=new CTabOne;
m_tabPages[1]=new CTabTwo;
m_tabPages[2]=new CTabThree;
m_nNumberOfPages=3;
}
RegisterKontrolle::~Regist
{
//------------------------
for(int nCount=0; nCount<m_nNumberOfPages; nCount++)
{
delete m_tabPages[nCount];
}
//------------------------
}
BEGIN_MESSAGE_MAP(Register
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// RegisterKontrolle-Meldungs
//########################
void RegisterKontrolle::Registe
{
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_
m_tabPages[1]->Create(IDD_
m_tabPages[2]->Create(IDD_
m_tabPages[0]->ShowWindow(
m_tabPages[1]->ShowWindow(
m_tabPages[2]->ShowWindow(
RegisterAufbau();// Funktion aufrufen
}
//########################
void RegisterKontrolle::Registe
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPo
for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
{
m_tabPages[nCount]->SetWin
}
}
//########################
void RegisterKontrolle::OnLButt
{
// TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein, und/oder benutzen Sie den Standard.
CTabCtrl::OnLButtonDown(nF
if(m_tabCurrent != GetCurFocus())
{
m_tabPages[m_tabCurrent]->
m_tabCurrent=GetCurFocus()
m_tabPages[m_tabCurrent]->
m_tabPages[m_tabCurrent]->
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Alex,
now it works. I changed the CMyTabCtrl into RegisterKontrolle.
I forgot to change CMyTabCtrl m_myTabCtrl; into Registerkontrolle m_myTabCtrl.
The only (I hope simple)problem now=>
when I change the tabs on the tab register, the new dialogs are in th upper left side
of my screen of Visual C++ Net and not in the tab control.
Please let me know. Thanks Alex.
Best regards,
Thomas
now it works. I changed the CMyTabCtrl into RegisterKontrolle.
I forgot to change CMyTabCtrl m_myTabCtrl; into Registerkontrolle m_myTabCtrl.
The only (I hope simple)problem now=>
when I change the tabs on the tab register, the new dialogs are in th upper left side
of my screen of Visual C++ Net and not in the tab control.
Please let me know. Thanks Alex.
Best regards,
Thomas
ASKER
Hi Alex,
I just had to change some setting for each DialogBox IDD_DIALOG1-IDD_DIALOG3.
Now everything works just fine.
Thanks for your great help.
I have just added 500 points for you.
Have a great day.
Best regards,
Thomas
I just had to change some setting for each DialogBox IDD_DIALOG1-IDD_DIALOG3.
Now everything works just fine.
Thanks for your great help.
I have just added 500 points for you.
Have a great day.
Best regards,
Thomas
Does this happen in CodeGuru sample? CMyTabCtrl::SetRectangle function must do the work.
ASKER
No the CodeGuru sample works just fine.
I just wanted to create a new project with the code for me.
I just wanted to create a new project with the code for me.
You need to use CMyTabCtrl class directly in your project. Maybe you made some mistake copying the code.