Question

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();

 }

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

i google for modelss dialog .note that message in msdn.com

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

note:This sample uses a very simple mechanism: It performs delete this in PostNcDestroy — a function that is called after the nonclient area of the box has been destroyed.

but that's in MFC .I use it for WTL . when delete this; it will be asserted 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 right way that delete the pointer to a modeless dialog ?

Thank your help!

DONE:

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

OnFinalMessage is WTL's equivalent to MFC's PostNCDestroy and you can safely let your frame window "suicide" in there :)

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

that works!

Was it helpful?

Solution

OnFinalMessage is WTL's equivalent to MFC's PostNCDestroy and you can safely let your frame window "suicide" in there.

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

OTHER TIPS

Per the MSDN documentation:

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

"To arrange for closing and deleting a modeless dialog box, override PostNcDestroy and invoke the delete operator on the this pointer."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top