CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Sep 2007
    Posts
    18

    CTabCtrl initiating Dialog problem

    This is what I used to derive from the CTabCtrl class:
    Code:
    IMPLEMENT_DYNCREATE(CDialogTabs, CDialog)
    
    CDialogTabs::CDialogTabs(CWnd* pParent /*=NULL*/)
    	: CDialog(CDialogTabs::IDD)
    {
    	m_DialogID[0] = IDD_EDIT_TISSUE;
    	m_DialogID[1] = IDD_EDITCVECTOR;
    	m_DialogID[2] = IDD_EDITCELLTYPE;
    }
    
    void CDialogTabs::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	DDX_Control(pDX, IDC_TAB1, tab1);
    }
    
    BOOL CDialogTabs::OnInitDialog( )
    {
    	CimDBManagerDoc *pDoc = (CimDBManagerDoc *) theApp.m_pDoc;
    	CDialog::OnInitDialog();
    
    	TC_ITEM TabCtrlItem;
    	CRect WindowRect;
    	TabCtrlItem.mask = TCIF_TEXT;
    	TabCtrlItem.pszText = _T("Edit Cell Type");
    	if(tab1.InsertItem(0,&TabCtrlItem)==-1)
    		MessageBox(_T("InsertItem 1 failed"));
    	TabCtrlItem.pszText = _T("Edit Construct Vector");
    	if(tab1.InsertItem(0,&TabCtrlItem)==-1)
    		MessageBox(_T("InsertItem 2 failed"));
    	TabCtrlItem.pszText = _T("Edit Tissue");
    	if(tab1.InsertItem(0,&TabCtrlItem)==-1)
    		MessageBox(_T("InsertItem 3 failed"));
    
    	//Determine the size of the area for the contents
    	tab1.GetClientRect(&m_ClientRect);
    	tab1.AdjustRect(FALSE, &m_ClientRect);
    
    	//Determine the offset within the view's client area
    	tab1.GetWindowRect(&WindowRect);
    	GetParent()->ScreenToClient(WindowRect);
    	m_ClientRect.OffsetRect(WindowRect.left-15, WindowRect.top-40);
    
    	//Complete the initialization
    	tab1.SetCurSel(0);
    	CreateContents();
    
    	return TRUE;
    }
    
    BEGIN_MESSAGE_MAP(CDialogTabs, CDialog)
    	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CDialogTabs::OnSelchangeTab)
    END_MESSAGE_MAP()
    
    void CDialogTabs::CreateContents()
    {
    	int	CurSel = tab1.GetCurSel();
    	if(m_Dialog.m_hWnd)
    		m_Dialog.DestroyWindow();
    	if(!m_Dialog.Create(m_DialogID[CurSel], &tab1))
    		TRACE0("Dialog not created\n");
    	m_Dialog.MoveWindow(m_ClientRect);
    	m_Dialog.ShowWindow(SW_SHOW);
    	GetParent()->RedrawWindow();
    }
    
    void CDialogTabs::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
    {
    	CreateContents();
    }
    And one of the dialogs I inserted into the tab1 is:
    Code:
    // CEditTissue dialog
    
    IMPLEMENT_DYNAMIC(CEditTissue, CDialog)
    
    CEditTissue::CEditTissue(CWnd* pParent /*=NULL*/)
    	: CDialog(CEditTissue::IDD, pParent)
    	, m_tThickness(_T(""))
    {
    }
    
    void CEditTissue::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	...
    	DDX_Control(pDX, IDC_TISSUEPATIENT, m_tPatient1);
    	...
    }
    
    BOOL CEditTissue::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    	GetPatientList();
    	return TRUE;
    }
    
    ...
    
    // CEditTissue message handlers
    void CEditTissue::GetPatientList()
    {
    	if (!m_dbPatient.IsOpen())
    		m_dbPatient.Open();
    	m_dbPatient.m_strFilter = _T("");
    	m_dbPatient.Requery();
    
    	while(m_dbPatient.IsOpen()&&!m_dbPatient.IsEOF())
    	{
    		m_tPatient1.AddString(m_dbPatient.m_Name);
    		m_dbPatient.MoveNext();
    	}
    
    	m_dbPatient.Close();
    }
    (m_dbPatient here is a CRecordSet)

    The tabs seems fine. When I clicked on them, the window will toggle through the 3 dialogs.

    But if I put a breakpoint on BOOL CEditTissue::OnInitDialog();
    The application never go to this initialization. So the
    GetPatientList(); never gets to run.
    in EditTissue.h I have:
    Code:
     protected:
    	virtual BOOL OnInitDialog( );
    My guess is the m_Dialog.ShowWindow(SW_SHOW) only display the CEditTissue Dialog, but not like DoModel() will actually run the class.

    Could anybody give me a hint of how to solve this?


    Thanks,
    Last edited by tajepe; October 15th, 2007 at 01:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured