How to destroy several instances of a dialog-derived class?
-
Let's say my application has a pointer to a CDialog derived class and I create some modeless dialogs.(More than one!). My question is how to destroy all of them - myPointer->DestroyWindow() - for the last created one and after that how to redirect the pointer to the rest of the dialogs in order to destroy all of them?
-
Let's say my application has a pointer to a CDialog derived class and I create some modeless dialogs.(More than one!). My question is how to destroy all of them - myPointer->DestroyWindow() - for the last created one and after that how to redirect the pointer to the rest of the dialogs in order to destroy all of them?
You can use DestroyWindow() to delete the underlying MFC windows handle. Obviously, if you use this on a dialog this will delete all the underlying child handles associated with that dialog box. Another method is to use PostMessage(WM_CLOSE, 0, 0), which is the method I prefer. To destroy a chain of dialog associated with each other you could try SendMessageToSiblings(WM_CLOSE). This will filter through a dialog box chain sending the message to each sibling (To be honst I've never used this method so I don't know if it will work). If you wanted to get all object orientated about it you could look at using the composite design pattern. This design pattern is used to forming complex tree structures and works brillantly for distributing messages across its tree structure.