I have to say that if you're doing this then your design is almost certainly wrong.
Why should a window need to access its grandparent window ? In fact it shouldn't need to access its parent either. This is causing an upwards dependency between child and parent which is bad.
I'd rethink your design - think about passing a data structure into the child windows for them to change. Then use a windows message (or even better the observer pattern) if parents need to know of changes in child windows.
Darwen.
www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.
Another way to approach this is to take a 'data centric' approach. That is, rather than worrying about parent/child/grandchild relationships, the child dialogs act on 'document' data.
If the child dialogs initialize and update their data to a common document they are free to be able to be called in any order.
See the attached sample for an MFC dialog application that displays two child dialogs with all dialogs updating their data to a common document.
Here are the details:
First we borrow from the MFC Doc/View architecture idea and create a simple 'Document' class:
Next in the main dialog, we create a member pointer to the CDataDocument class and initialize it in the OnInitDialog override
Code:
BOOL CMainDlg::OnInitDialog()
{
// Create and initialize our 'document'
// Since the document pointer is used in the DoDataExchange call, we
// need to create the document before calling the base OnInitDialog( )
m_pDataDocument = new CDataDocument( _T("Arjay"), _T("Seattle, WA"), 10 );
CDialog::OnInitDialog();
// Other standard initialization done here
return TRUE;
}
For each control, add a DDX data variable of the proper type, and then modify each entry to point to the data document. (Don't forget to delete
the each member variable in the header file because they are no longer
used)
You can see that using this approach and leveraging DDX, there isn't much code to write, no complicated Parent/Grandparent relationships or message passing.
The code ends up being quite compact. P.S. You can use this same approach when working with PropertySheet/PropertyPages to really simplify things.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.