Re: GetParent() from a modal dialog in a MFC SDI application
Hi David,
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
itself.
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.
Tom
"David Webber" <dave@musical-dot-demon-dot-co.uk> wrote in message
news:OLTy4CQrHHA.4100@TK2MSFTNGP06.phx.gbl...
"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:1181658365.493717.151160@z28g2000prd.googlegroups.com...
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 &m_view;
public
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 :-)
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm