Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Access CFormView vars from CMainFrame

Access CFormView vars from CMainFrame

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel1324
    wrote on last edited by
    #1

    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 S 2 Replies Last reply
    0
    • D Daniel1324

      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 Offline
      I Offline
      ian mariano
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • I ian mariano

        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

        D Offline
        D Offline
        Daniel1324
        wrote on last edited by
        #3

        Thanks for the reply.

        1 Reply Last reply
        0
        • D Daniel1324

          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

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          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

          I 1 Reply Last reply
          0
          • S 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

            I Offline
            I Offline
            ian mariano
            wrote on last edited by
            #5

            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's CanCloseView() (or whatever you call it) into your override of CanCloseFrame():

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups