modeless dialogs

I have a veiw from where i am calling a modeless dialog. In the view handler i have allocated memmory for this dialog dynamically. I can delete this object in either view's destructor or when the dialog box sends user defined message to the view. But the thing is when dialog box should send this user defined message.
1. shoud the dialog box send this user defined message on pressing OK button or Cancel button or some other button.
In modeless dialog box what action should be taken in Ok button and Cancel button

2. What does the PostNcDestroy member function have to do with modeless dialog

3. I found an example where view dynamically allocates memmory for modeless dialog and this dynamic object is not destroyed anywhere in the view.

But i found that in the modeless diaglog box there's postncdestroy member function in which " delete this" statememnt is made. The question is will this statement deletes the dynamically allocated object for modeless dialog box whose memmory is allocated in the view.
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.

delete this in PostNCDestroy is one of possible implementations for modeless dialog.
It is the self-destructed dialog. You are free to select this method or call delete pDialog; in your code in other place.

In OnOk(), OnCalcel() you should do DestroyWindow() because the default MFC implementation for modeless dialogs does not destroy window within this functions.

  I think your problem is you don't
when and where you should delete
the window object,because you don't
know when user'll close the window.
  I think you couldn't use "new"
operator to allocate memory dynamiclly,
because you don't know where to
put "delete" operator.
  I don't think user-defined message
is good solution to your problem.
I have ever try that.
  May you should try following code.

1. add following line to the
definiton of your window object

   CRuntimeClass *p=RUNTIME_CLASS(CShowWin);
   CObject *pObject = p->CreateObject();
   ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CShowWin ) ) );

when the user close window, system
will free memory automatcally.
  Just try that, Good Luck!

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

I agree with vachooho's comment,

You can create your Modeless in View and delete it in the PostNcDestroy() of that dialog Class, which will clean up the memory that was allocated, In this situation your base class implementation of OnOk and OnCancel will call the PostNcDestroy and so you have cleared the memory in either case.

I do not know about LioBin's way, but you can give it a try and if it works do let us all know of it.

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.