Click here to Skip to main content
15,893,904 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
(btw - no harm in starting a new thread with offshoot topics like this Smile | :) )

This question takes you into the fun and exciting world of Classic Win32. Well, perhaps i'm being generous with "fun and exciting"... but anyway...

In a nutshell, this is how it works: in basic ol' Win32 (and Win16 for that matter), dialogs are not quite the same as "regular" windows. They aren't created in the same way, they don't get passed messages in the same way, and the default behavior for unprocessed messages isn't the same either. MFC does a lot to hide this from you, but at its core it still behaves in much the same way. Which makes things interesting when you're creating a non-modal by deriving a class from CDialog, because you inherit a lot of defaults that you really don't want.
And one of those behaviors is what happens when you call ::DefWindowProc() with WM_CLOSE as the message. As you've found, dialogs do not call DestroyWindow() - they post WM_COMMAND with WPARAM set to 2 (IDCANCEL). And because the message is posted, you don't get a nice call stack leading back to OnClose() from OnCancel().
Why is this so? Because you don't close dialogs - real modal dialogs - by calling DestroyWindow(). They have their own message loops that need to be cleaned up, and those take care of actually destroying the window, so you call EndModalLoop() in MFC, or EndDialog() in Win32. And that is what the default behavior for OnClose()/OnOk() end up doing... which as you've noticed, is nearly useless for non-modal dialogs.

----
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_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 
AnswerRe: Multiple instance like MS Word Pin
David Crow15-Feb-06 3:47
David Crow15-Feb-06 3:47 
GeneralRe: Multiple instance like MS Word Pin
Anilkumar K V15-Feb-06 17:04
Anilkumar K V15-Feb-06 17:04 
GeneralRe: Multiple instance like MS Word Pin
ThatsAlok16-Feb-06 2:38
ThatsAlok16-Feb-06 2:38 

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.