destroying a modeless dialog

If I put "delete this" in the PostNcDestroy function, do I still need to do other stuff in the OnOK and OnCancel functions for a modeless dialog, or does the "delete this" in the PostNcDestroy function take care of everything?
huyaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

I dont think we have to do any more clean up as PostNcDestroy() and OnNcDestroy() functions are the last member functions that are called. Those functions will do the default cleanup. But if U have used some pointers and allocated memory, then U have to delete(or free ) the memory.

For further information about those functions U can look into the OnLine help of those functions(U might have already seen that!)

delete this; will delete the this pointer and object. But if u have allocated some memory as I said, then it will not be deleted. That memory should be deleted by U in the code explicitly.
0
vachoohoCommented:
delete this will call your dialog's destructor. If you have any allocated memory you must delete it also (VinExpert right).

But the problem in that PostNCDestroy will not be called from OnOk() and OnCancel() handlers if your dialog is modeless.

Thus you need call DestroyWindow() within OnOk() and OnCancel() handlers. This will bring up the call to PostNCDestroy() , delete this (in PostNCDestroy()) will be called, then your dialog's destructor will make all the rest clean-up (if neccesary)

Hope this helps
0
wyy_cqCommented:
i do this in CYourDlg::OnDestroy()
and it work fine. OnDestroy() called after OnOK/OnCancel.

but i recommand that you post a message to a frame window (who create the dialog) and put the object point as LPARAM parameter. the frame delete the object when it recevie the message.
sample code:

CYourDlg::OnDestroy(...)
{
    pFrame->PostMessage(WM_YOUR_MSG,0,(LPARAM)this);
........
}

in the frame window
LONG CYourFrame::OnYourMessage(WPARAM wP,LPARAM lP)
{
  delete ((CYourDlg*)lP);
  return;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.