Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Techies,

I've just started to work on CTabCtrl, with a dialog Property Page. Initially, I've taken an empty dialog and then took a TabCtrl from Toobox and then I ve taken another resource ie the Dialog Property Sheet(Medium) and on that I've sepcified my required controls.

Then I could attach property page to the base dialog ie on the First Tab of TabCtrl successfully, but after that I need to add another Tab & for that I've taken another Dialog Property Sheet,I've done that in the similar way, but I am getting some debug assertions messages and the output displayes with corresponding Dialog with a two tabs, but the issue is, once I click the newly created second tab, the application hangs.

Please suggest..is that anything else to be done for the second tab to make it working and avoid hanging of the appln.

Regards,
Techie.
Posted

Please observe the following routing :) :
BEGIN_MESSAGE_MAP(CYourDialog, CDialog)
  ON_NOTIFY(TCN_SELCHANGING, IDC_TAB1, OnSelchangingTab)
  ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab)
END_MESSAGE_MAP()


BOOL CYourDialog::OnInitDialog()
{
  BOOL bResult(CDialog::OnInitDialog());

  m_cTabControl.ModifyStyleEx(0, WS_EX_CONTROLPARENT);

  m_cGeneralPage.Create(CPhaseGeneralPage::sm_uiResourceID, NULL);
  m_cGeneralPage.SetParent(&m_cTabControl);
  m_cGeneralPage.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
  m_cTabControl.InsertItem(TCIF_TEXT|TCIF_PARAM,
                           0,
                           _T("first"),
                           (LPARAM) &m_cGeneralPage);

  m_cParameterPage.Create(CPhaseParameterPage::sm_uiResourceID, NULL);
  m_cParameterPage.SetParent(&m_cTabControl);
  m_cParameterPage.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
  m_cTabControl.InsertItem(TCIF_TEXT|TCIF_PARAM,
                           1,
                           _T("second"),
                           0,
                           (LPARAM) &m_cParameterPage);

  m_cUserPage.Create(CPhaseUserPage::sm_uiResourceID, NULL);
  m_cUserPage.SetParent(&m_cTabControl);
  m_cUserPage.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
  m_cTabControl.InsertItem(TCIF_TEXT|TCIF_PARAM,
                           2,
                           _T("third"),
                           0,
                           (LPARAM) &m_cUserPage);
  AdjustContent();
  ActivatePage(0, true);

  return bResult;
}

void CYourDialog::AdjustContent()
{
  m_cTabControl.GetClientRect(&cRect);
  cRect.DeflateRect(2, 22, 3, 2); // could be improved... :)

  int iCount(m_cTabControl.GetItemCount());
  while (iCount--) {
    TCITEM tcItem;
    tcItem.mask = TCIF_PARAM;
    if (m_cTabControl.GetItem(iCount, &tcItem)) {
      if (tcItem.lParam) {
        CDialog* pcPage = (CDialog*) tcItem.lParam;
        pcPage->MoveWindow(&cRect, FALSE);
      }
    }
  }
}

void CYourDialog::OnSelchangingTab(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
  ActivatePage(m_cTabControl.GetCurSel(), false);
  *pResult = 0;
}

void CPhaseEditDialog::OnSelchangeTab(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
  ActivatePage(m_cTabControl.GetCurSel(), true);
  *pResult = 0;
}

void CYourDialog::ActivatePage(int iPage, bool bActivate)
{
  TCITEM tcItem;
  tcItem.mask = TCIF_PARAM;
  if (m_cTabControl.GetItem(iPage, &tcItem)) {
    if (tcItem.lParam) {
      CDialog* pcPage = (CDialog*) tcItem.lParam;
      if (bActivate) {
        pcPage->UpdateData(FALSE);
        pcPage->ShowWindow(SW_SHOW);
        pcPage->SetFocus();
      } else {
        pcPage->UpdateData(TRUE);
        pcPage->ShowWindow(SW_HIDE);
      }
    }
  }
}
 
Share this answer
 
thank you Eugen for your support.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900