Creating/Adding Tabs to a Tab Control
-
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
-
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
-
That's an idea. Thanks. - monrobot13