Access CFormView vars from CMainFrame
-
I have an SDI program, and I need to access the variables in CFormView from CMainFrame. I cant figure out how to do that. I'm catching WM_CLOSE in CMainFrame, and whether or not the program will be allowed to close will depend on a variable thats in CFormView. So, I need to access this variable from CMainFrame. Any help? Thanks, Daniel
-
I have an SDI program, and I need to access the variables in CFormView from CMainFrame. I cant figure out how to do that. I'm catching WM_CLOSE in CMainFrame, and whether or not the program will be allowed to close will depend on a variable thats in CFormView. So, I need to access this variable from CMainFrame. Any help? Thanks, Daniel
Actually, you can expose a get accessor to your property.
BOOL GetAllowClosing() { // return TRUE / FALSE depending on the variable }
You can get at in CMainFrame by:
CFormView pForm = (CFormView)GetActiveView();
Then you just use the return the value of
pForm->GetAllowClosing()
Ian Mariano - http://www.ian-space.com/
"We are all wave equations in the information matrix of the universe" - me -
Actually, you can expose a get accessor to your property.
BOOL GetAllowClosing() { // return TRUE / FALSE depending on the variable }
You can get at in CMainFrame by:
CFormView pForm = (CFormView)GetActiveView();
Then you just use the return the value of
pForm->GetAllowClosing()
Ian Mariano - http://www.ian-space.com/
"We are all wave equations in the information matrix of the universe" - meThanks for the reply.
-
I have an SDI program, and I need to access the variables in CFormView from CMainFrame. I cant figure out how to do that. I'm catching WM_CLOSE in CMainFrame, and whether or not the program will be allowed to close will depend on a variable thats in CFormView. So, I need to access this variable from CMainFrame. Any help? Thanks, Daniel
You may be reinventing the wheel. CDocument has CanCloseFrame(), which currently checks the dirty bit of the document and then prompts if you want to save. You can override this, and have the document ask the form if it's OK to close, and return false if not. You then don't need to handle WM_CLOSE in CMainFrame, unless you need to for other reasons. Steve S
-
You may be reinventing the wheel. CDocument has CanCloseFrame(), which currently checks the dirty bit of the document and then prompts if you want to save. You can override this, and have the document ask the form if it's OK to close, and return false if not. You then don't need to handle WM_CLOSE in CMainFrame, unless you need to for other reasons. Steve S
Steve S is right, Daniel. It actually makes things easier than handling
WM_CLOSE
in the Main Frame, although that's perfectly OK as well... Just inject the check on your CFormView derived View'sCanCloseView()
(or whatever you call it) into your override ofCanCloseFrame()
:BOOL CMyDocument::CanCloseFrame(CFrameWnd* pFrame) { // check your view first CMyFormView pView = (CMyFormView)pFrame->GetActiveView(); if (FALSE == pView->CanCloseView()) return FALSE; // ok, since it's OK to close after that check, call the base implementation return CDocument::CanCloseFrame(pFrame); }
Ian Mariano - http://www.ian-space.com/
"We are all wave equations in the information matrix of the universe" - me