Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:15:30+00:00 2026-06-08T21:15:30+00:00

I created a simple tab control that has 2 tabs (each tab is a

  • 0

I created a simple tab control that has 2 tabs (each tab is a different dialog). The thing is that i don’t have any idea how to switch between tabs (when the user presses Titlu Tab1 to show the dialog i made for the first tab, and when it presses Titlu Tab2 to show my other dialog). I added a handler for changing items, but i don’t know how should i acces some kind of index or child for tabs.

Tab1.h and Tab2.h are headers for dialogs that show only static texts with the name of the each tab.

There may be an obvious answer to my question, but i am a real newbie in c++ and MFC.

This is my header:

// CTabControlDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "Tab1.h"
#include "Tab2.h"


// CCTabControlDlg dialog
class CCTabControlDlg : public CDialog
{
// Construction
public:
   CCTabControlDlg(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
enum { IDD = IDD_CTABCONTROL_DIALOG };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation
protected:
   HICON m_hIcon;

  // Generated message map functions
  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_tabcontrol1;

  CTab1 m_tab1;
  CTab2 m_tab2;
  afx_msg void OnTcnSelchangeTabcontrol(NMHDR *pNMHDR, LRESULT *pResult);
};

And this is the .cpp:

// CTabControlDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CTabControl.h"
#include "CTabControlDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
 public:
   CAboutDlg();

 // Dialog Data
  enum { IDD = IDD_ABOUTBOX };

  protected:
  virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

 // Implementation
 protected:
    DECLARE_MESSAGE_MAP()
 };

 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
 {
 }

 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
 {
   CDialog::DoDataExchange(pDX);
 }

 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 END_MESSAGE_MAP()


 // CCTabControlDlg dialog




 CCTabControlDlg::CCTabControlDlg(CWnd* pParent /*=NULL*/)
   : CDialog(CCTabControlDlg::IDD, pParent)
 {
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 }

 void CCTabControlDlg::DoDataExchange(CDataExchange* pDX)
 {
  CDialog::DoDataExchange(pDX);
  DDX_Control(pDX, IDC_TABCONTROL, m_tabcontrol1);
 }

 BEGIN_MESSAGE_MAP(CCTabControlDlg, CDialog)
  ON_WM_SYSCOMMAND()
  ON_WM_PAINT()
  ON_WM_QUERYDRAGICON()
  //}}AFX_MSG_MAP
  ON_NOTIFY(TCN_SELCHANGE, IDC_TABCONTROL,         &CCTabControlDlg::OnTcnSelchangeTabcontrol) 
    END_MESSAGE_MAP()


   // CCTabControlDlg message handlers

  BOOL CCTabControlDlg::OnInitDialog()
  {
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
{
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
        pSysMenu->AppendMenu(MF_SEPARATOR);
        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon

// TODO: Add extra initialization here

CTabCtrl* pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TABCONTROL);

m_tab1.Create(IDD_TAB1, pTabCtrl);

TCITEM item1;
item1.mask      = TCIF_TEXT | TCIF_PARAM;
item1.lParam    = (LPARAM)& m_tab1;
item1.pszText   = _T("Titlu Tab1");
pTabCtrl->InsertItem(0, &item1);

//Pozitionarea dialogului
CRect rcItem;
pTabCtrl->GetItemRect(0, &rcItem);
m_tab1.SetWindowPos(NULL, rcItem.left, rcItem.bottom + 1, 0, 0, SWP_NOSIZE | SWP_NOZORDER );

m_tab1.ShowWindow(SW_SHOW);

// al doilea tab
m_tab2.Create(IDD_TAB2, pTabCtrl);
TCITEM item2;
item2.mask      = TCIF_TEXT | TCIF_PARAM;
item2.lParam    = (LPARAM)& m_tab1;
item2.pszText   = _T("Titlu Tab2");
pTabCtrl->InsertItem(0, &item2);

//Pozitionarea dialogului
//CRect rcItem;
pTabCtrl->GetItemRect(0, &rcItem);
m_tab2.SetWindowPos(NULL, rcItem.left, rcItem.bottom + 1, 0, 0, SWP_NOSIZE | SWP_NOZORDER );

m_tab2.ShowWindow(SW_SHOW);

return TRUE;  // return TRUE  unless you set the focus to a control
  }

  void CCTabControlDlg::OnSysCommand(UINT nID, LPARAM lParam)
  {
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
}
else
{
    CDialog::OnSysCommand(nID, lParam);
}
    }

  // If you add a minimize button to your dialog, you will need the code below
  //  to draw the icon.  For MFC applications using the document/view model,
  //  this is automatically done for you by the framework.

  void CCTabControlDlg::OnPaint()
  {
if (IsIconic())
{
    CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()),   0);

    // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
}
else
{
    CDialog::OnPaint();
}
  }

  // The system calls this function to obtain the cursor to display while the user drags
  //  the minimized window.
  HCURSOR CCTabControlDlg::OnQueryDragIcon()
  {
   return static_cast<HCURSOR>(m_hIcon);
  }


  void CCTabControlDlg::OnTcnSelchangeTabcontrol(NMHDR *pNMHDR, LRESULT *pResult)
  {
// TODO: Add your control notification handler code here
*pResult = 0;

   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:15:31+00:00Added an answer on June 8, 2026 at 9:15 pm

    You can do this automatically in MFC by making the parent dialog a CPropertySheet and the contained dialogs CPropertyPage.

    With the way you have it structured currently, you should do a ShowWindow for each of the dialogs with one set to SW_SHOW and the other to SW_HIDE in your OnTcnSelchangeTabcontrol function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view (user control) that has tab control and tab items in
I have tab controller created through storyboards with a custom implementation (simple buttons and
I created a simple Sudoku application, where each 3x3 squares is a user control,
I am looking for a tab control that is different from the default NSTabControl.
I've created a simple facebook app that can run as a tab on a
I have idea to implement my wpf windows like TabPages in tab control. It
I want to create a Tab Control that only opens content once. Each item
I have been going crazy over a problem with my tab control. It has
I've created a simple user control in Windows Forms that consists of a button
Could someone help me on this, I have created simple web services using axis2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.