Re: CDialog Messaging Practice Question
Thanks for the replies. Joe, I was using your modeless dialogs done right
essay to design my dialog, and I have basically a mirror image of your
example in my code. I added an override to OnClose() because you cover OnOK
and OnCancel, but OnClose is triggered if the user clicks the red X. Other
than that, same same.
So, I have a problem. I added the OnDestroy handler to send the message to
the parent, in order to set the pointer to NULL in the parent class, but no
matter how I do this, GetParent() in the dialog returns the CMainFrame.
when I trigger the dialog it goes like this.
///////////////////////
CMyDialog* pDlg = new CMyDialog(this) // this is a CView derived object
pDlg->Document( GetDocument() );
if( !pDlg->Create(this) )
{
error crap here
}
pDlg->ShowWindow(SW_SHOW);
//////////////////////////
twice I have sent 'this' to the dialog and GetParent() does not return it.
is there a reason why?
The only way I have founf to overcome this is because I have sent the this
pointer into the dialog, the dialog member m_pParentWnd is a pointer to my
CView derived object and I COULD call
m_pParentWnd->PostMessage(MESSAGE)
I can do this all the way up the PostNcDestroy function just before I call
'delete this' on the dialog. Is this the best way to accomplish this?
thanks
Andy
"asellon" <asellon@cox.net> wrote in message
news:Jp2Kk.319$bK.219@newsfe04.iad...
I have a CDialog derived class that is modeless and is specifically
designed to be an interface into a few variables stored in my document. I
am electing to pass the dialog a pointer to my document prior to showing it
due to initialization of the parameters in the box, but I was playing
around with the idea of using messaging to completely decouple the dialog
from the application. Which honestly might be asinine, since the dialog
only has control members and I am specifically sending the values to the
document for storage at the moment they are changed. I could have values
parameters in the dialog and simply move them across, but I didn't want to
do it that way, mostly because I don't need to store them in the dialog.
The idea is you make a change in the dialog, and it is reflected in the
application immediately. So sending a message seemed like a plausible
idea, but it does not answer the dialog initialization question very well..
Anyway... moving on.
Using GetParent()->PostMessage(...) in the dialog posts a message to the
mainframe. ON_MESSAGE macros do not route like command messages, so the
frame does not forward this on to views or anything else.
What might be a good practice here? Post the message to the frame and
then have a handler in the frame that posts the message to the view?
Change the message to a WM_COMMAND message and allow it to route that way?
Just curious, but for the purposes of the application I am working on, the
pointer to the document solves the problem the best given the current code
I have been handed.
So.. I guess this is a discussion post. Ideas?