-
October 15th, 2007, 01:54 PM
#1
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.
-
October 15th, 2007, 02:02 PM
#2
Re: CTabCtrl initiating Dialog problem
What kind of variable is m_Dialog ?
-
October 15th, 2007, 03:05 PM
#3
Re: CTabCtrl initiating Dialog problem
If the OnInitDialog() isn't behaving like you would expect, is there any disadvantage to just calling m_Dialog.OnInitDialog() in you CreateContents() function after you have called Create() ?
"Live only for tomorrow, and you will have a lot of empty yesterdays today."
-
October 15th, 2007, 03:09 PM
#4
Re: CTabCtrl initiating Dialog problem
Originally Posted by tmecham
If the OnInitDialog() isn't behaving like you would expect, is there any disadvantage to just calling m_Dialog.OnInitDialog() in you CreateContents() function after you have called Create() ?
That is not good. OnInitDialog is supposed to have got called. Doing what you suggest will only hide the real issue.
Also, OnInitDialog is not to be called from outside the class, hence if you check the MFC signature, it is declared protected and not public
-
October 15th, 2007, 03:15 PM
#5
Re: CTabCtrl initiating Dialog problem
The problem is if the issue is an MFC bug/feature in which case you might have to brute force the init. I can see not calling OnInitDialog() but you could create a base class with a MyInit() or something that you could call after each tab is created to do the initialization that you need and leave the CDialog::OnInitDialog() to do it's own thing.
"Live only for tomorrow, and you will have a lot of empty yesterdays today."
-
October 15th, 2007, 03:37 PM
#6
Re: CTabCtrl initiating Dialog problem
Originally Posted by kirants
What kind of variable is m_Dialog ?
Sorry, this is the declaration:
Code:
public:
int m_DialogID[3];
CRect m_ClientRect;
CDialog m_Dialog;
-
October 15th, 2007, 03:40 PM
#7
Re: CTabCtrl initiating Dialog problem
There you go. You are instantiating a CDialog object. If you do that, there is no CEditTissue object at all. So, how would the class' code even get called. Your object should be of class CEditTissue if it has to receive the OnInitDialog.
-
October 15th, 2007, 03:51 PM
#8
Re: CTabCtrl initiating Dialog problem
Got ya. You hit the point.
Thank you, both of you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|