首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于非模态对话框关闭有关问题?

2012-01-13 
关于非模态对话框关闭问题?????????创建一个非模态的对话框,当我需要关闭它时,先调用postMessage(WM_CLOSE

关于非模态对话框关闭问题?????????
创建一个非模态的对话框,当我需要关闭它时,先调用postMessage(WM_CLOSE),然后调用在OnClose里面调用Destroywindow(),此时程序能够正常的退出;但是当我直接调用Destroywindow()而不是在OnClose里面调用;此时调用Destroywindow会发生ASSERT;具体的代码如下:
BOOL   CWnd::DestroyWindow()
{
CWnd*   pWnd;
CHandleMap*   pMap;
HWND   hWndOrig;
BOOL   bResult;

if   ((m_hWnd   ==   NULL)   &&   (m_pCtrlSite   ==   NULL))
return   FALSE;

bResult   =   FALSE;
pMap   =   NULL;
pWnd   =   NULL;
hWndOrig   =   NULL;
if   (m_hWnd   !=   NULL)
{
pMap   =   afxMapHWND();//该MAP为空,为什么呢?????
ASSERT(pMap   !=   NULL);
pWnd   =   (CWnd*)pMap-> LookupPermanent(m_hWnd);
#ifdef   _DEBUG
hWndOrig   =   m_hWnd;
#endif
}

#ifdef   _AFX_NO_OCC_SUPPORT
if   (m_hWnd   !=   NULL)
bResult   =   ::DestroyWindow(m_hWnd);
#else   //_AFX_NO_OCC_SUPPORT
if   ((m_hWnd   !=   NULL)   ||   (m_pCtrlSite   !=   NULL))
{
if   (m_pCtrlSite   ==   NULL)
bResult   =   ::DestroyWindow(m_hWnd);
else
bResult   =   m_pCtrlSite-> DestroyControl();
}
#endif   //_AFX_NO_OCC_SUPPORT

if   (hWndOrig   !=   NULL)
{
//   Note   that   'this '   may   have   been   deleted   at   this   point,
//     (but   only   if   pWnd   !=   NULL)
if   (pWnd   !=   NULL)
{
//   Should   have   been   detached   by   OnNcDestroy
#ifdef   _DEBUG
ASSERT(pMap-> LookupPermanent(hWndOrig)   ==   NULL);
#endif
}
afxMapHWND()的返回值为空,我并没有清空该MAP表啊,谢谢大家帮我解释一下。。。

[解决办法]
...
[解决办法]
倒是贴了不少代码,不知道你到底想问什么。

如果是想关闭对话框的话,不需要自己调用DestroyWindow(),调用CDialog::OnCancel()或者CDialog::OnOk()就可以了。

热点排行