Modeless CPropertySheet destruction?
-
Greetings, My problem is that I am spawning multiple modeless CPropertySheet dialogs from my application but the closure of the CPropertySheet dialog does not destroy the pages that have been added. I can see from the trace statements that the destructors for the individual pages are called but if I try to re-spawn the CPropertySheet I find it already has pages added???? I have tried creating my own class and using the following code in the destructor
while (this->GetPageCount()) { this->RemovePage(this->GetPageCount()); }
This compiles ok but fails on execution. Where am I going wrong? Many thanks
Alan
-
Greetings, My problem is that I am spawning multiple modeless CPropertySheet dialogs from my application but the closure of the CPropertySheet dialog does not destroy the pages that have been added. I can see from the trace statements that the destructors for the individual pages are called but if I try to re-spawn the CPropertySheet I find it already has pages added???? I have tried creating my own class and using the following code in the destructor
while (this->GetPageCount()) { this->RemovePage(this->GetPageCount()); }
This compiles ok but fails on execution. Where am I going wrong? Many thanks
Alan
Try this as the WM_DESTROY handler for the property sheet -
BOOL CPropsSheet::DestroyWindow()
{
for (int p = GetPageCount () - 1;p > -1;p--)
RemovePage (p);return CPropertySheet::DestroyWindow();
}
I suspect the problem lies in your RemovePage call. The page count page indices are 0-based;
RemovePage(GetPageCount())
is trying to remove a non-existent page. [edit] edit for clarity [/edit]L u n a t i c F r i n g e
modified on Tuesday, March 9, 2010 7:19 PM
-
Greetings, My problem is that I am spawning multiple modeless CPropertySheet dialogs from my application but the closure of the CPropertySheet dialog does not destroy the pages that have been added. I can see from the trace statements that the destructors for the individual pages are called but if I try to re-spawn the CPropertySheet I find it already has pages added???? I have tried creating my own class and using the following code in the destructor
while (this->GetPageCount()) { this->RemovePage(this->GetPageCount()); }
This compiles ok but fails on execution. Where am I going wrong? Many thanks
Alan
Hi, 1. aren't the tab pages numbered from 0 to count-1, which would mean you are (not) removing a non-existing page forever? 2. you could remove the first tab page in a loop, until none remain. simpler code, the drawback is tab pages now could move on the screen while your loop executes. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
Hi, 1. aren't the tab pages numbered from 0 to count-1, which would mean you are (not) removing a non-existing page forever? 2. you could remove the first tab page in a loop, until none remain. simpler code, the drawback is tab pages now could move on the screen while your loop executes. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
Using the DestroyWindow seems to work fine and taking into accout the base for the count makes all the difference ;) ( Doh!) Thank you both.
Alan