MDI UpdateAllViews
-
RoboTed wrote: What I want is for "AllDocs" to "UpdateAllViews". Invalidate() the MDI Client window. If that doesn't work you could: a) iterate all docs and call UpdateAllView() for each one. b) iterate all MDI Client window.children and Invalidate each one. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
My problem is that I don't know alot about MFC. What is "the MDI Client window" and how do I get to it ? How do I "iterate all docs" ? Which class owns the docs ? If I can't find a function in the help files, then I won't know where to find it. There is no "GetFirstDocument" function, or a "GetFirstView", especially for an MDI app. All I am doing (for now) is handling a menu message ( change color ) which opens a CColorDialog and let's me pick a color. I want ALL my views to use the new color.
-
My problem is that I don't know alot about MFC. What is "the MDI Client window" and how do I get to it ? How do I "iterate all docs" ? Which class owns the docs ? If I can't find a function in the help files, then I won't know where to find it. There is no "GetFirstDocument" function, or a "GetFirstView", especially for an MDI app. All I am doing (for now) is handling a menu message ( change color ) which opens a CColorDialog and let's me pick a color. I want ALL my views to use the new color.
Here is some code to scan all views. If you want code to scan all docs or all MDI children let me know.
/** Run 'Scan_Func' for each Template.Document.View * * @param pTemplate Ptr to Template whose document -> views are are to be scanned. * If NULL scan Text windows. * @param Scan_Func Ptr to CEDTextView method to call for each view * @param iVar1 int to pass on to Scan_Func as param 1 * * @see <A HREF="d:\ED32\EDDoc.cpp#^CEDDoc::ScanDocs"> * @caller VwProperties(), VwRedraw() * * @return if Scan_Func returns false stop scanning and return current pCEDTextView, * else return NULL */ CEDTextView* // static CEDTextView::ScanViews( SECMultiDocTemplate* pTemplate, int(CEDTextView::*Scan_Func)( int ), int iVar1 ) { // TODO: change this to use GetDocument()->GetDocTemplate() and remove app code. // need docking view in own CEDOutputDoc. Also remove static from function // so GetDocument() can be called. if ( pTemplate == NULL ) { CEDApp* pApp = (CEDApp*)AfxGetApp(); ASSERT_VALID( pApp ); pTemplate = pApp->GetTemplate( IDR_EDTYPE ); // scan Text Windows } ASSERT( pTemplate != NULL ); // We iterate through each document for this template // and then each view for each document. POSITION Dpos = pTemplate->GetFirstDocPosition(); while ( Dpos != NULL ) { CEDDoc* pDoc = (CEDDoc*)pTemplate->GetNextDoc( Dpos ); if ( pDoc->DocGetVmb() != NULL ) { POSITION Vpos = pDoc->GetFirstViewPosition(); while ( Vpos != NULL ) { CEDTextView* pView = (CEDTextView*)pDoc->GetNextView( Vpos ); ASSERT( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) ); if ( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) ) // if Scan_Func returns false stop scanning and return current pCEDTextView, if ( !(pView->*Scan_Func)( iVar1 ) ) return pView; } } } return NULL; // scanned all views } // example scan function int CEDTextView::VwDraw( int iOpts ) { ..... } // example use CEDTextView::ScanViews( pTemplate, VwDraw, 0 );
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
Well, consider Visual Studio. If you have 5 source files open ( the documents ), and you go and change the text color in the options menu, ALL the views will update. The color of the text being displayed in the view is common to ALL views. It is NOT part of the data.
What you described was nothing like this. You described a piece of data belonging to one view whose change you wanted announced to other views. What you're comparing to in VS is a global setting used with all views. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
My problem is that I don't know alot about MFC. What is "the MDI Client window" and how do I get to it ? How do I "iterate all docs" ? Which class owns the docs ? If I can't find a function in the help files, then I won't know where to find it. There is no "GetFirstDocument" function, or a "GetFirstView", especially for an MDI app. All I am doing (for now) is handling a menu message ( change color ) which opens a CColorDialog and let's me pick a color. I want ALL my views to use the new color.
RoboTed wrote: There is no "GetFirstDocument" function, or a "GetFirstView", especially for an MDI app Instead of telling us what there isn't - when you clearly don't know - you might try following the advice of those that have done this. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
RoboTed wrote: There is no "GetFirstDocument" function, or a "GetFirstView", especially for an MDI app Instead of telling us what there isn't - when you clearly don't know - you might try following the advice of those that have done this. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson"The point of doc/view and the UpdateAllViews feature is that you're storing the data in the document. When that data is updated, calling UpdateAllViews allerts all views working with that data that it has changed." Yes, I know that. I have used "UpdateAllViews". I get it. As I said before, I am asking how I can update ALL views in my App, not just the ones related to one document. Changing the text color has nothing to do with "the data in the document", it relates to how the view displays it. Therefore, the textcolor is a static member in my view class and has a static access function. Once I change the color variable, I need all the views in my App to redraw themselves. Simply calling UpdateAllViews will only update the views attached to that ONE document.
-
Here is some code to scan all views. If you want code to scan all docs or all MDI children let me know.
/** Run 'Scan_Func' for each Template.Document.View * * @param pTemplate Ptr to Template whose document -> views are are to be scanned. * If NULL scan Text windows. * @param Scan_Func Ptr to CEDTextView method to call for each view * @param iVar1 int to pass on to Scan_Func as param 1 * * @see <A HREF="d:\ED32\EDDoc.cpp#^CEDDoc::ScanDocs"> * @caller VwProperties(), VwRedraw() * * @return if Scan_Func returns false stop scanning and return current pCEDTextView, * else return NULL */ CEDTextView* // static CEDTextView::ScanViews( SECMultiDocTemplate* pTemplate, int(CEDTextView::*Scan_Func)( int ), int iVar1 ) { // TODO: change this to use GetDocument()->GetDocTemplate() and remove app code. // need docking view in own CEDOutputDoc. Also remove static from function // so GetDocument() can be called. if ( pTemplate == NULL ) { CEDApp* pApp = (CEDApp*)AfxGetApp(); ASSERT_VALID( pApp ); pTemplate = pApp->GetTemplate( IDR_EDTYPE ); // scan Text Windows } ASSERT( pTemplate != NULL ); // We iterate through each document for this template // and then each view for each document. POSITION Dpos = pTemplate->GetFirstDocPosition(); while ( Dpos != NULL ) { CEDDoc* pDoc = (CEDDoc*)pTemplate->GetNextDoc( Dpos ); if ( pDoc->DocGetVmb() != NULL ) { POSITION Vpos = pDoc->GetFirstViewPosition(); while ( Vpos != NULL ) { CEDTextView* pView = (CEDTextView*)pDoc->GetNextView( Vpos ); ASSERT( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) ); if ( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) ) // if Scan_Func returns false stop scanning and return current pCEDTextView, if ( !(pView->*Scan_Func)( iVar1 ) ) return pView; } } } return NULL; // scanned all views } // example scan function int CEDTextView::VwDraw( int iOpts ) { ..... } // example use CEDTextView::ScanViews( pTemplate, VwDraw, 0 );
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
What you described was nothing like this. You described a piece of data belonging to one view whose change you wanted announced to other views. What you're comparing to in VS is a global setting used with all views. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
"The point of doc/view and the UpdateAllViews feature is that you're storing the data in the document. When that data is updated, calling UpdateAllViews allerts all views working with that data that it has changed." Yes, I know that. I have used "UpdateAllViews". I get it. As I said before, I am asking how I can update ALL views in my App, not just the ones related to one document. Changing the text color has nothing to do with "the data in the document", it relates to how the view displays it. Therefore, the textcolor is a static member in my view class and has a static access function. Once I change the color variable, I need all the views in my App to redraw themselves. Simply calling UpdateAllViews will only update the views attached to that ONE document.
Then you need to use an object that is accessable across all your views/documents. The first one that comes to mind is the application object which can be obtained via AfxGetApp. By the way, unless you lose the attitude I doubt you'll get much more help around here. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
I said a "static" variable in the class. It does NOT belong to one view, it belongs ( is shared by ) ALL instances of that view class.
You were not very clear about whether or not this was a single view type or if you had other view types. At any rate, people like myself freely give our time to help others as a gesture of community spirit. Your rudeness surely won't help you garner much help around here. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson -
You were not very clear about whether or not this was a single view type or if you had other view types. At any rate, people like myself freely give our time to help others as a gesture of community spirit. Your rudeness surely won't help you garner much help around here. Cheers, Tom Archer Inside C#,
Extending MFC Applications with the .NET Framework It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen SigvardssonSorry if I sound rude, or "have an attitude". I thought I was perfectly clear in the original question when I said -- What I want is for "AllDocs" to "UpdateAllViews" --. "Instead of telling us what there isn't - when you clearly don't know - you might try following the advice of those that have done this." There is no function called "GetFirstDocument". If I "clearly don't know", then maybe someone should tell Microsoft, becuase they neglected to put it in the help files. I would love nothing more than to follow your advice, that is why I originally posted the question. "Then you need to use an object that is accessable across all your views/documents. The first one that comes to mind is the application object which can be obtained via AfxGetApp." Sorry to be "rude" again, but that still doesn't answer the question. So now I have a pointer to CMyApp, ok, what do I do to get all the documents and UpdateAllViews ? My point here is that your not giving me advice, your giving me half answers that never solve the original problem. I apologize for my attitude, I did not intend to offend anyone, I just wanted to know how other applications update every view in the app. I wanted to know how other software engineers have implemented a " UpdateAllInstantiatedViewsInTheApp() " function.
-
Perfect !!! GetFirstDocPosition and GetNextDoc is exactlly what I was looking for !!! Thank You so much !!!!
RoboTed wrote: Thank You so much !!!! Glad to be of help. Oh and thanks for the thankyou. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com