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
Solved

How to create a TabControl 500 Points....please help

Posted on 2006-11-15
10
170 Views
Last Modified: 2010-04-24
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;
}
//#####################################################
0
Comment
Question by:tsp2002
  • 5
  • 5
10 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17947381
0
 

Author Comment

by:tsp2002
ID: 17947591
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 17947769
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:tsp2002
ID: 17955353
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17955424
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
 

Author Comment

by:tsp2002
ID: 17955645
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
 

Author Comment

by:tsp2002
ID: 17955732
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 17955780
Does this happen in CodeGuru sample? CMyTabCtrl::SetRectangle function must do the work.
0
 

Author Comment

by:tsp2002
ID: 17956277
No the CodeGuru sample works just fine.
I just wanted to create a new project with the code for me.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17958931
You need to use CMyTabCtrl class directly in your project. Maybe you made some mistake copying the code.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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