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::OnTcnSelchangeRegister(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;
}
//#####################################################
Thomas StockbrueggerAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
What error exactly?

To change m_myTabCtrl type from CTabCtrl to CMyTabCtrl, you need to add line
#include "CMyTabCtrl.h"
to dialog h-file:

// TabControl_ClassDlg.h : Headerdatei
//

#pragma once
#include "afxcmn.h"

#include "RegisterKontrolle.h"
#include "CMyTabCtrl.h"

class CTabControl_ClassDlg : public CDialog
{
    ....

//     CTabCtrl m_myTabCtrl;
     CMyTabCtrl m_myTabCtrl;
};

0
 
Thomas StockbrueggerAuthor Commented:
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.



0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
AlexFMCommented:
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.
0
 
Thomas StockbrueggerAuthor Commented:
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.RegisterAuswahl();        //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_DIALOG };

      protected:
      virtual void DoDataExchange(CDataExchange* 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(RegisterKontrolle, CTabCtrl)
RegisterKontrolle::RegisterKontrolle()

{
      m_tabPages[0]=new CTabOne;
      m_tabPages[1]=new CTabTwo;
      m_tabPages[2]=new CTabThree;
      m_nNumberOfPages=3;
}

RegisterKontrolle::~RegisterKontrolle()
{
      //--------------------------------------------------
      for(int nCount=0; nCount<m_nNumberOfPages; nCount++)
      {
            delete m_tabPages[nCount];
      }
      //--------------------------------------------------

}


BEGIN_MESSAGE_MAP(RegisterKontrolle, CTabCtrl)
      ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()



// RegisterKontrolle-Meldungshandler

//#################################################
void RegisterKontrolle::RegisterAuswahl()
{
      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::RegisterAufbau()
{
      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]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
      for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
      {
            m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
      }
}
//###################################################################
void RegisterKontrolle::OnLButtonDown(UINT nFlags, CPoint point)
{
      // TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein, und/oder benutzen Sie den Standard.

      CTabCtrl::OnLButtonDown(nFlags, 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();
      }
}



0
 
Thomas StockbrueggerAuthor Commented:
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



0
 
Thomas StockbrueggerAuthor Commented:
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

0
 
AlexFMCommented:
Does this happen in CodeGuru sample? CMyTabCtrl::SetRectangle function must do the work.
0
 
Thomas StockbrueggerAuthor Commented:
No the CodeGuru sample works just fine.
I just wanted to create a new project with the code for me.
0
 
AlexFMCommented:
You need to use CMyTabCtrl class directly in your project. Maybe you made some mistake copying the code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.