PostNcDestroy problems
-
Hi there, I am having trouble with my dialogues using the cross X in the corner of my dialogue doesn't seem to call PostNcDestroy where I perform clean up of the object. I was expecting the WM_CLOSE message to be generated which calls the default DestroyWindow. Can anyone explain why it is not being called? Andy
-
Hi there, I am having trouble with my dialogues using the cross X in the corner of my dialogue doesn't seem to call PostNcDestroy where I perform clean up of the object. I was expecting the WM_CLOSE message to be generated which calls the default DestroyWindow. Can anyone explain why it is not being called? Andy
Interesting. I have a modeless dialog I use in a little app that simply shows a progress bar while the app is running. When I click the 'X', it indeed calls the dialog's PostNcDestroy() function.
-
Hi there, I am having trouble with my dialogues using the cross X in the corner of my dialogue doesn't seem to call PostNcDestroy where I perform clean up of the object. I was expecting the WM_CLOSE message to be generated which calls the default DestroyWindow. Can anyone explain why it is not being called? Andy
I don't think it is called in modal dialogs. John
-
I don't think it is called in modal dialogs. John
I don't understand it, I stepped through some of the example code in Nishants tutorial and closing the dialogue with the X definitely calls PostNcDestroy, however it doesn't in mine, despite the fact that clicking the X sends the WM_CLOSE message, which I think should call destroy window. I'm confused, the only difference I can see in my code is that I call ShowWindow in the constructor of my dialogue, and not in the external code. ?? Andy :-( Still confused
-
I don't understand it, I stepped through some of the example code in Nishants tutorial and closing the dialogue with the X definitely calls PostNcDestroy, however it doesn't in mine, despite the fact that clicking the X sends the WM_CLOSE message, which I think should call destroy window. I'm confused, the only difference I can see in my code is that I call ShowWindow in the constructor of my dialogue, and not in the external code. ?? Andy :-( Still confused
Is your dialog modeless then? John
-
Is your dialog modeless then? John
It's definetly modeless, I create a new dialogue like this
if(!m_pDlgComms) // check to see if the dialogue exists
{
m_pDlgComms = new CCommsDlg(this);etc which is then constructed like this
CCommsDlg::CCommsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCommsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCommsDlg)
m_sCommsInput = _T("");
m_sCommsOutput = _T("");
//}}AFX_DATA_INIT
if (Create(CCommsDlg::IDD, pParent))
{
m_pParent = pParent;
ShowWindow(SW_SHOW);
}
}and here is the PostNcDestroy which is called whenever I force a destroy window using a button for example
void CCommsDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
if(m_pParent)
{((CBuggycontrolappView\*)m\_pParent)->m\_pDlgComms = NULL; ((CBuggycontrolappView\*)m\_pParent)->m\_nCommsToggleState = 0; } delete this;
}
but not when I use the cross. Even though there is a WM_CLOSE message Andy
-
It's definetly modeless, I create a new dialogue like this
if(!m_pDlgComms) // check to see if the dialogue exists
{
m_pDlgComms = new CCommsDlg(this);etc which is then constructed like this
CCommsDlg::CCommsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCommsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCommsDlg)
m_sCommsInput = _T("");
m_sCommsOutput = _T("");
//}}AFX_DATA_INIT
if (Create(CCommsDlg::IDD, pParent))
{
m_pParent = pParent;
ShowWindow(SW_SHOW);
}
}and here is the PostNcDestroy which is called whenever I force a destroy window using a button for example
void CCommsDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
if(m_pParent)
{((CBuggycontrolappView\*)m\_pParent)->m\_pDlgComms = NULL; ((CBuggycontrolappView\*)m\_pParent)->m\_nCommsToggleState = 0; } delete this;
}
but not when I use the cross. Even though there is a WM_CLOSE message Andy
Ok, I understand your problem but I have not seen this in the past. Do you have code for OnCancel() ? Destroying the window with the X button should call OnCancel(). John
-
It's definetly modeless, I create a new dialogue like this
if(!m_pDlgComms) // check to see if the dialogue exists
{
m_pDlgComms = new CCommsDlg(this);etc which is then constructed like this
CCommsDlg::CCommsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCommsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCommsDlg)
m_sCommsInput = _T("");
m_sCommsOutput = _T("");
//}}AFX_DATA_INIT
if (Create(CCommsDlg::IDD, pParent))
{
m_pParent = pParent;
ShowWindow(SW_SHOW);
}
}and here is the PostNcDestroy which is called whenever I force a destroy window using a button for example
void CCommsDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
if(m_pParent)
{((CBuggycontrolappView\*)m\_pParent)->m\_pDlgComms = NULL; ((CBuggycontrolappView\*)m\_pParent)->m\_nCommsToggleState = 0; } delete this;
}
but not when I use the cross. Even though there is a WM_CLOSE message Andy
When WM_CLOSE is sent, you need to send call DestroyWindow() For example:
CCommsDlg::OnClose()
{
DestroyWindow();
}This is how you close a modeless dialog. When you call DestroyWindow() then of course you will get to PostNcDestroy(). // Afterall I realized that even my comment lines have bugs
-
When WM_CLOSE is sent, you need to send call DestroyWindow() For example:
CCommsDlg::OnClose()
{
DestroyWindow();
}This is how you close a modeless dialog. When you call DestroyWindow() then of course you will get to PostNcDestroy(). // Afterall I realized that even my comment lines have bugs
Hello again guys I've solved the problem I think. I put in the handler for WM_CLOSE, and the following code
void CCommsDlg::OnClose()
{
CDialog::OnClose();DestroyWindow();
}
This now works fine, doing exactly what I want. Previously the code I had used was
void CCommsDlg::OnClose()
{
DestroyWindow();CDialog::OnClose();
}
which gave me the exception. I'm still not sure why though no doubt one of you guys can inform me and I'm still puzzled by the fact that the code given in Nishants example in the dialogues section makes no call to OnClose at all and still calls
PostNcDestroy
. However now my code works I'm a happy man :-) though it'd be better if I understood why! Cheers Andy -
Hello again guys I've solved the problem I think. I put in the handler for WM_CLOSE, and the following code
void CCommsDlg::OnClose()
{
CDialog::OnClose();DestroyWindow();
}
This now works fine, doing exactly what I want. Previously the code I had used was
void CCommsDlg::OnClose()
{
DestroyWindow();CDialog::OnClose();
}
which gave me the exception. I'm still not sure why though no doubt one of you guys can inform me and I'm still puzzled by the fact that the code given in Nishants example in the dialogues section makes no call to OnClose at all and still calls
PostNcDestroy
. However now my code works I'm a happy man :-) though it'd be better if I understood why! Cheers AndyAs Nishant explains in his article a modal dialog makes a call to DestroyWindow() and as a result to PostNcDestroy(). But in your example you are building a modeless dialog and Windows is very specific about this case. You need to call DestroyWindow() to close a modeless dialog. Why? I don't know. This decision was made by windows. I will do a little bit of investigating though to find out. However, in this case OnClose() doesn't generate an WM_DESTROY message afterwards. And by the way this part of your code DestroyWindow(); CDialog::OnClose(); generates an exception because you are sending a WM_CLOSE message to a window that doesn't exist. // Afterall I realized that even my comment lines have bugs