This article is part of the drag and drop interface samples.
- Serializing ASCII Data
- Modeless child dialog
- Modeless sibling dialog
- The drag source
- The MFC drop target
- The TBTextTarget class
Download source files - 20 Kb
It's nearly as short as the child version of modeless
dialogs
Follow these steps:
- Create a new dialog resource and use the Class Wizard for making a
new CDialog based class COtherDropDialog
- In the class maintaining the modeless dialog (here it's CInterfaceView)
add a member variable of type pointer to CWinThread and make sure you
have a destructor:
<font color="#000080">class</font> CInterfaceView : public CView
{
...
CWinThread *m_pDlgThread
~CInterfaceView();
...
}
- Use ClassWizard to create a new CWinThread-based class COtherDropDialogThread
- Override COtherRopDialogThread::InitInstance():
If you forget to change the m_pMainWnd variable, the dialog will stay
modal!
BOOL COtherDropDialogThread::InitInstance()
{
COtherDropDialog dlg;
m_pMainWnd = &dlg;
dlg.DoModal(); <font color="#008000">
return FALSE;
}
- In your appropriate message handler, do the following:
<FONT COLOR=#008080>void</FONT> CInterfaceView::OnFileOthermodeless()
{
<FONT COLOR=#008000> <FONT COLOR=#008000> <FONT COLOR=#008000> <FONT COLOR=#008000> <FONT COLOR=#804040>if</FONT> (AfxIsValidAddress(m_pDlgThread, <FONT COLOR=#804040>sizeof</FONT>(CWinThread)) &&
AfxIsValidAddress(m_pDlgThread->m_pMainWnd, <FONT COLOR=#804040>sizeof</FONT>(CWnd)))
{
<FONT COLOR=#804040>if</FONT> (::IsWindow(m_pDlgThread->m_pMainWnd->GetSafeHwnd()))
{ m_pDlgThread->GetMainWnd()->SetWindowPos(
&wndTop, <FONT COLOR=#aa6400>0</FONT>,<FONT COLOR=#aa6400>0</FONT>,<FONT COLOR=#aa6400>0</FONT>,<FONT COLOR=#aa6400>0</FONT>,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
<FONT COLOR=#804040>return</FONT>;
}
}
<FONT COLOR=#008000> m_pDlgThread=AfxBeginThread( RUNTIME_CLASS(COtherDropDialogThread) );
}
- If you like your top-level window to have an icon displayed in the
taskbar, add the following to COtherDropDialog:: OnInitDialog (ommited
in the sample):
BOOL COtherDropDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
<font color="#008000"> </font>}
- Don't forget to do the clean-up in the destructor:
CInterfaceView::~CInterfaceView()
{
<font color="#000080">if</font> (AfxIsValidAddress(m_pDlgThread, <font color="#000080">sizeof</font>(CWinThread)) &&
AfxIsValidAddress(m_pDlgThread->m_pMainWnd, <font color="#000080">sizeof</font>(CWnd)))
{
CDialog *pDlg = (CDialog *)m_pDlgThread->m_pMainWnd;
<font color="#000080">if</font> (::IsWindow(pDlg->GetSafeHwnd()))
{
<font color="#008000"> </font> ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CDialog)));
pDlg->EndDialog(IDCANCEL);
<font color="#008000"> </font> WaitForSingleObject(m_pDlgThread->m_hThread, 2000);
m_pDlgThread=NULL;
}
}
}
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here