Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating/Adding Tabs to a Tab Control

Creating/Adding Tabs to a Tab Control

Scheduled Pinned Locked Moved C / C++ / MFC
saleshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monrobot13
    wrote on last edited by
    #1

    I'm looking to make a dialog based program that utilizes a tab control and I'm looking for the best way to go about this. Currently I have the main dialog with the tab control on it and I've created two child dialogs to add to the tab pages. This is how I add the pages, and switch between them in my code. To me it doesn't look like the best way to do things so I was hoping to get some ideas on a better way to go about this. Here is the code:

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

    m\_tabData.InsertItem (0, " Media Sales ");
    m\_tabData.InsertItem (1, " Price Information ");
    VERIFY (m\_dlgSales.Create (IDD\_MEDIASALES\_DIALOG, this));
    VERIFY (m\_dlgPrice.Create (IDD\_PRICE\_DIALOG, this));
    CRect rectCtrl;
    GetDlgItem (FRAME\_TAB\_DIALOG)->GetWindowRect (&rectCtrl);
    ScreenToClient (&rectCtrl);
    m\_dlgSales.MoveWindow (&rectCtrl, TRUE);
    m\_dlgSales.BringWindowToTop ();
    m\_dlgSales.ShowWindow (SW\_SHOW);
    m\_dlgSales.SetFocus ();
    	
    return FALSE;
    

    }

    void CDataManDlg::OnTabSelected(NMHDR* pNMHDR, LRESULT* pResult)
    {
    // Set a new current tab.
    int nCurrentTab = m_tabData.GetCurSel ();

    // Hide all the tabs.
    m\_dlgSales.ShowWindow (SW\_HIDE);
    m\_dlgPrice.ShowWindow (SW\_HIDE);
    
    // Get window of visible tabbed dialog.
    CWnd\* pWndCurrentTab = NULL;
    switch (nCurrentTab) {
    case 0:
    	pWndCurrentTab = &m\_dlgSales;
    	break;
    case 1:
    	pWndCurrentTab = &m\_dlgPrice;
    	break;
    default:
    	ASSERT (FALSE);
    	break;
    }
    
    // Resize and show the dialog
    if (pWndCurrentTab != NULL) {
    	CRect rectCtrl;
    	GetDlgItem (FRAME\_TAB\_DIALOG)->GetWindowRect (&rectCtrl);
    	ScreenToClient (&rectCtrl);
    
    	pWndCurrentTab->MoveWindow (&rectCtrl, TRUE);
        pWndCurrentTab->ShowWindow (SW\_SHOW);
    	pWndCurrentTab->Invalidate ();
    	pWndCurrentTab->UpdateWindow ();
    	pWndCurrentTab->BringWindowToTop ();
    	pWndCurrentTab->SetFocus ();
    }
    
    \*pResult = 0;
    

    }

    One thing that really bothers me is I have to have a staic control on the form that is sized to the tab control - minus the tabs (FRAME_TAB_DIALOG) in order to have the child dialogs sized correctly. This doesn't seem like a good way to do things. Any help and/or ideas would be greatly appreciated. Thanks. - monrobot13

    C 1 Reply Last reply
    0
    • M monrobot13

      I'm looking to make a dialog based program that utilizes a tab control and I'm looking for the best way to go about this. Currently I have the main dialog with the tab control on it and I've created two child dialogs to add to the tab pages. This is how I add the pages, and switch between them in my code. To me it doesn't look like the best way to do things so I was hoping to get some ideas on a better way to go about this. Here is the code:

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

      m\_tabData.InsertItem (0, " Media Sales ");
      m\_tabData.InsertItem (1, " Price Information ");
      VERIFY (m\_dlgSales.Create (IDD\_MEDIASALES\_DIALOG, this));
      VERIFY (m\_dlgPrice.Create (IDD\_PRICE\_DIALOG, this));
      CRect rectCtrl;
      GetDlgItem (FRAME\_TAB\_DIALOG)->GetWindowRect (&rectCtrl);
      ScreenToClient (&rectCtrl);
      m\_dlgSales.MoveWindow (&rectCtrl, TRUE);
      m\_dlgSales.BringWindowToTop ();
      m\_dlgSales.ShowWindow (SW\_SHOW);
      m\_dlgSales.SetFocus ();
      	
      return FALSE;
      

      }

      void CDataManDlg::OnTabSelected(NMHDR* pNMHDR, LRESULT* pResult)
      {
      // Set a new current tab.
      int nCurrentTab = m_tabData.GetCurSel ();

      // Hide all the tabs.
      m\_dlgSales.ShowWindow (SW\_HIDE);
      m\_dlgPrice.ShowWindow (SW\_HIDE);
      
      // Get window of visible tabbed dialog.
      CWnd\* pWndCurrentTab = NULL;
      switch (nCurrentTab) {
      case 0:
      	pWndCurrentTab = &m\_dlgSales;
      	break;
      case 1:
      	pWndCurrentTab = &m\_dlgPrice;
      	break;
      default:
      	ASSERT (FALSE);
      	break;
      }
      
      // Resize and show the dialog
      if (pWndCurrentTab != NULL) {
      	CRect rectCtrl;
      	GetDlgItem (FRAME\_TAB\_DIALOG)->GetWindowRect (&rectCtrl);
      	ScreenToClient (&rectCtrl);
      
      	pWndCurrentTab->MoveWindow (&rectCtrl, TRUE);
          pWndCurrentTab->ShowWindow (SW\_SHOW);
      	pWndCurrentTab->Invalidate ();
      	pWndCurrentTab->UpdateWindow ();
      	pWndCurrentTab->BringWindowToTop ();
      	pWndCurrentTab->SetFocus ();
      }
      
      \*pResult = 0;
      

      }

      One thing that really bothers me is I have to have a staic control on the form that is sized to the tab control - minus the tabs (FRAME_TAB_DIALOG) in order to have the child dialogs sized correctly. This doesn't seem like a good way to do things. Any help and/or ideas would be greatly appreciated. Thanks. - monrobot13

      C Offline
      C Offline
      Carlos Antollini
      wrote on last edited by
      #2

      Yesterday, was a question like that, but a guy had a lot of control and he couldn't manage all of them... I said him the better is using CPropertieSheet class with CPropertiePage.... Regards Carlos Antollini Do you know piFive[^] ?

      M 1 Reply Last reply
      0
      • C Carlos Antollini

        Yesterday, was a question like that, but a guy had a lot of control and he couldn't manage all of them... I said him the better is using CPropertieSheet class with CPropertiePage.... Regards Carlos Antollini Do you know piFive[^] ?

        M Offline
        M Offline
        monrobot13
        wrote on last edited by
        #3

        That's an idea. Thanks. - monrobot13

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups