?
Solved

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

Posted on 2006-11-15
10
Medium Priority
?
186 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
 

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
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.

 

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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

830 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