I've just dug out the assignment I mentioned above. It contains a modeless dialog using MFC, as this was one of the assessment areas for the assignment.
There are a few things you need to do for the modeless dialog, that I can show you here:
First, you need a class for the dialog itself, which contains:
1. A pointer to its parent. (For example, a view.)
I did this by adding a CView* to the dialog's constructor.
2. A Create() override method, to create the actual dialog, as follows:
BOOL CModelessDlg::Create()
{
// Create the dialog.
return CDialog::Create(CModelessDlg::IDD, m_pParent);
// Where m_pParent is the CView* passed to the constructor.
}
3. A PostNcDestroy() override method, as follows:
void CModelessDialog::PostNcDestroy()
{
// Delete the dialog.
delete this;
CDialog::PostNcDestroy();
}
4. An OnClose() override.
void CModelessDlg::OnClose()
{
// Set the parent's dialog pointer to NULL.
((CWhatever*)m_pParent)->m_pModelessDlg = NULL;
// Destroy the window.
DestroyWindow();
}
Then, in your parent class, you will need:
1. A pointer to the dialog, such as:
CModelessDialog* m_pModelessDlg;
2. A function for creating, or "switching to" the modeless dialog:
void CWhatever::OnShowModelessDlg()
{
if(!m_pModelessDlg)
{
// Create the dialog.
m_pModelessDlg = new CModelessDlg(this);
m_pModelessDlg->Create();
}
else
// Set the dialog active.
m_pModelessDlg->SetActiveWindow();
}
I hope that helps, but I know it's hard to understand if you are new to MFC. I'll try and answer any questions that you may have.
kirkl_uk
PS: Sorry this is such a long post. Give those scrolling muscles some action tho eh!?