Link to home
Start Free TrialLog in
Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany

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::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;
}
//#####################################################
Avatar of AlexFM
AlexFM

Avatar of Thomas Stockbruegger

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.



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.
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();
      }
}



ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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



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

Does this happen in CodeGuru sample? CMyTabCtrl::SetRectangle function must do the work.
No the CodeGuru sample works just fine.
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.