How to remove a pointer to a modeless dialog in WTL

in MainDlg function

LRESULT CMainDlg::OnDo(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { CMyDlg* dlg = new CMyDlg;// it could be CMainDlg member var //dlg.pMain = this; // i want to SendMessage(pMain.m_hWnd...) in CMyDlg...but it don't // work... dlg->Create(m_hWnd); dlg->ShowWindow(SW_SHOW); return 0; } 

in CMyDlg

  class CMyDlg : public CDialogImpl<CMyDlg>, public CUpdateUI<CMyDlg>, public CMessageFilter, public CIdleHandler, public CWinDataExchange<CMyDlg>, public CDialogResize<CMyDlg> LRESULT CMyDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { DestroyWindow(); } 

therefore the pointer CMyDlg * dlg will be lost ... (memory leak)

i google for dialogue of models. Mark this post at msdn.com

http://msdn.microsoft.com/en-us/library/zhk0y9cw(VS.80).aspx

note: This example uses a very simple mechanism: it deletes this in PostNcDestroy - a function that is called after the non-client area of ​​a field has been destroyed.

but it is in MFC. I use it for WTL. when remove it; he will be approved on

 virtual ~CWindowImplRoot() { #ifdef _DEBUG if(m_hWnd != NULL) // should be cleared in WindowProc { ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n")); ATLASSERT(FALSE); } #endif //_DEBUG } 

SO:

What is the correct way to remove a pointer to a modeless dialog?

Thank you for your help!

MADE:

http://tech.groups.yahoo.com/group/wtl/message/4444

OnFinalMessage is equivalent to the WTL MFC PostNCDestroy, and you can safely let your suicide window frame there :)

 void CSetRecordInfoDlg::OnFinalMessage( HWND /*hWnd*/ ) { delete this; } 

which is working!

+4
source share
2 answers

OnFinalMessage is equivalent to the WTL MFC PostNCDestroy, and you can safely let your suicide window frame there.

include: http://tech.groups.yahoo.com/group/wtl/message/4444

+4
source

In the MSDN documentation:

"The default handlers call the EndDialog member function to close the dialog box. You can also call EndDialog from your own code ...

"To configure closing and deleting a dialog box without a model, override PostNcDestroy and invoke the delete operator on this pointer."

0
source

All Articles