Click here to Skip to main content
15,893,814 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
Tim Smith15-Feb-06 3:35
Tim Smith15-Feb-06 3:35 
GeneralRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
ThatsAlok16-Feb-06 2:43
ThatsAlok16-Feb-06 2:43 
GeneralRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
Tim Smith16-Feb-06 3:40
Tim Smith16-Feb-06 3:40 
GeneralRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
ThatsAlok16-Feb-06 17:24
ThatsAlok16-Feb-06 17:24 
AnswerRe: Sir,I want 2 know that weather we can call SAME function in Multiple Threads? Pin
BadKarma15-Feb-06 3:54
BadKarma15-Feb-06 3:54 
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 
Need your thoughts and/or opinion. Question at the bottom.

When user closes the modeless dialog box you can trap the WM_CLOSE message to insure proper cleanup.

According to Help
CWnd::OnClose
The framework calls this member function as a signal that the CWnd or an application is to terminate. The default implementation calls DestroyWindow.

I found two ways to approach the user who closes the modeless dialog box by clicking the x on the upper right hand corner of the window

Looking at the first example below.
I found out that if you don't call DestroyWindow() from your OnClose() and you don't want multiple instances of your modeless opened you will need to set the pointer to NULL here (otherwise your pointer value can't be used as a flag to prohibit other instances of your modeless dialog from being opened). PostNcDestroy apparently isn't run until the parent is destroyed. Once the parent/owner is closed then a PostNcDestroy is run for each modeless that opened - one right after another.

void CDialogDerived::OnClose()
{
CDialog::OnClose();
m_pParent->m_pModelessDialog = NULL;
}

void CDialogDerived::PostNcDestroy()
{
CDialog::PostNcDestroy();
m_pParent->m_pModelessDialog = NULL; //in case destroy window is called from your code and OnClose is never run
delete this;
}


Example 2. This seems like a cleaner approach as the Dialog is destroyed immediately and thus your pointer is set to
NULL immediately
void CDialogDerived::OnClose()
{
CDialog::OnClose();
DestroyWindow();
}

void CDialogDerived::PostNcDestroy()
{
CDialog::PostNcDestroy();
m_pParent->m_pModelessDialog = NULL;
delete this;
}

Any thoughts pro and con to either of these approaches? I'm curious why the PostNcDestroy is not run promptly
with the OnClose call on the first example.

Thanks!
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 
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 

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.