Re: GetParent() from a modal dialog in a MFC SDI application
I think the Apply button mostly signals the parent sheet to get the data
from the pages, but in this case OP had a CFormView that started up a modal
dialog. While it is possible to update the dialog, I still think that
accessing the parent directly to update controls would be the wrong way to
go about it. I would prefer sending messages and having the parent update
Still, most of the time, I would simply fish the data out of the dialog
object after the modal dialog is closed (if the user says OK) and not fish
the data out if the user canceled the modal dialog. Adding something like
an Apply button into the mix would change that paradigm though. OP didn't
mention having an Apply button on their modal dialog.
"David Webber" <email@example.com> wrote in message
"Ajay Kalra" <firstname.lastname@example.org> wrote in message
Why? Whats wrong in changing the view from the dialog? We did this
routinely. Instead of using GetParent, I used GetActiveView(thats what
we wanted) but thats besides the issue.
It should also be noted the modal property sheet dialogues have an "Apply"
button which is intended for exactly this purpose.
If I have dialogues which do this, and rely on having a CMyView as the
parent, I tend to write the constructor with an argument which is a
reference to a CMyView:
CMyDialog( CMyView &wndParent );
with a constructor broadly of the form
CMyDialog::CMyDialog( CMyView &wndParent )
: CDialog( &wndParent )
, m_view( wndParent )
That way the dialogue cannot be constructed without a view of the required
kind, and it can do what it likes to that view directly (using m_view)
while it lives.
I don't do this a lot, as it can be like a loaded gun with a hair trigger
pointed at one's foot <g> but one very useful example is setting margins
and other spacing on a page. The dialogue can change the settings in the
controls and they can be shown immediately on the view. Of course it
helps to have an implementation of Ctrl+Z for after you get out :-)
Author of 'Mozart the Music Processor'
For discussion/support see