Click here to Skip to main content
15,920,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
Stephen Hewitt15-Feb-06 16:59
Stephen Hewitt15-Feb-06 16:59 
AnswerRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
ThatsAlok16-Feb-06 2:41
ThatsAlok16-Feb-06 2:41 
Questionmodeless dialog WM_CLOSE - opinion Pin
23_44415-Feb-06 3:14
23_44415-Feb-06 3:14 
AnswerRe: modeless dialog WM_CLOSE - opinion Pin
Shog915-Feb-06 3:46
sitebuilderShog915-Feb-06 3:46 
AnswerRe: modeless dialog WM_CLOSE - opinion Pin
Rage15-Feb-06 3:59
professionalRage15-Feb-06 3:59 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44415-Feb-06 4:43
23_44415-Feb-06 4:43 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44415-Feb-06 4:58
23_44415-Feb-06 4:58 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
Shog915-Feb-06 7:53
sitebuilderShog915-Feb-06 7:53 
mx483 wrote:
1. Not Destroying your window till your parent is closed.

Sorry, i guess i missed that. Sounds like you're missing a few things in your implementation, so i'll go over the steps to doing a proper modeless dialog in MFC:
  1. Create with Create(), followed by ShowWindow(), not DoModal() (i'm sure you're already doing this Smile | :) )
  2. Never call EndModalLoop() (or EndDialog())
  3. Never let the default behavior run when it will end up doing what you avoided in #1 or #2
    • No default behavior for OnOK() or OnCancel() (WM_COMMAND handlers for IDOK and IDCANCEL)
    • Be aware that the default behavior for WM_CLOSE just posts a WM_COMMAND for IDCANCEL (so it'll end up calling IDCANCEL)
    • Be aware that various keys can trigger OnCancel()/OnOK() directly (ENTER, ESC) or indirectly (Alt+F4 -> WM_CLOSE -> OnCancel()). So you really do need to override these commands, even if you don't have an explicit IDOK or IDCANCEL button on your dialog.
So the likely explanation for the behavior you describe is that you're letting the baseclass call EndModalLoop(), which just hides the window. Then when the parent is destroyed, its (now hidden) children are also destroyed, causing the wave of delayed destruction you noticed.

So your fix is simple: override OnOK() and OnCancel() and cause them to call DestroyWindow() rather than the baseclass implementation. Optionally, do the same for OnClose() (isn't necessary, but will make it more obvious what you're doing).
And i'd still encourage you to avoid messing with data in the parent window class (and especially doing delete this). Nothing absolutely wrong with it, but it's messy - let the owner handle that stuff.



----
Scripts i've known...
CPhog 0.9.9 - make CP better.
Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve
Print forum 0.1.1 - printer-friendly forums

GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44415-Feb-06 8:00
23_44415-Feb-06 8:00 
AnswerRe: modeless dialog WM_CLOSE - opinion Pin
23_44416-Feb-06 5:17
23_44416-Feb-06 5:17 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
Shog916-Feb-06 10:32
sitebuilderShog916-Feb-06 10:32 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44416-Feb-06 10:39
23_44416-Feb-06 10:39 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
Shog916-Feb-06 10:45
sitebuilderShog916-Feb-06 10:45 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44416-Feb-06 11:15
23_44416-Feb-06 11:15 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
Shog916-Feb-06 11:32
sitebuilderShog916-Feb-06 11:32 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44416-Feb-06 11:49
23_44416-Feb-06 11:49 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
Shog916-Feb-06 12:25
sitebuilderShog916-Feb-06 12:25 
GeneralRe: modeless dialog WM_CLOSE - opinion Pin
23_44417-Feb-06 8:56
23_44417-Feb-06 8:56 
QuestionShades of a color Pin
DirA15-Feb-06 2:25
DirA15-Feb-06 2:25 
AnswerRe: Shades of a color Pin
Maximilien15-Feb-06 2:53
Maximilien15-Feb-06 2:53 
AnswerRe: Shades of a color Pin
Stephen Hewitt15-Feb-06 19:00
Stephen Hewitt15-Feb-06 19:00 
AnswerRe: Shades of a color Pin
Stephen Hewitt15-Feb-06 23:51
Stephen Hewitt15-Feb-06 23:51 
GeneralRe: Shades of a color Pin
DirA25-Feb-06 2:59
DirA25-Feb-06 2:59 
GeneralRe: Shades of a color Pin
Stephen Hewitt25-Feb-06 4:09
Stephen Hewitt25-Feb-06 4:09 
QuestionMultiple instance like MS Word Pin
Anilkumar K V15-Feb-06 1:54
Anilkumar K V15-Feb-06 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.