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 control variables and methods of other classes in SDI Application

Access control variables and methods of other classes in SDI Application

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresjson
7 Posts 4 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.
  • M Offline
    M Offline
    Maxim Zarus
    wrote on last edited by
    #1

    Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.

    P S 2 Replies Last reply
    0
    • M Maxim Zarus

      Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.

      P Offline
      P Offline
      Paresh Chitte
      wrote on last edited by
      #2

      Write your controling function in Application class (Derived from CWinApp).

      class CYourApp : public CWinApp
      {
      public:
         void YourControlingFunction();
      }
      
      //Wherever required use like this,
      
      CYourApp* pApp = (CYourApp*)AfxGetApp();
      if(NULL != pApp)
      {
         pApp->YourControlingFunction();
      }
      

      Hope this will serve your purpose. Regards, Paresh.

      M 1 Reply Last reply
      0
      • P Paresh Chitte

        Write your controling function in Application class (Derived from CWinApp).

        class CYourApp : public CWinApp
        {
        public:
           void YourControlingFunction();
        }
        
        //Wherever required use like this,
        
        CYourApp* pApp = (CYourApp*)AfxGetApp();
        if(NULL != pApp)
        {
           pApp->YourControlingFunction();
        }
        

        Hope this will serve your purpose. Regards, Paresh.

        M Offline
        M Offline
        Maxim Zarus
        wrote on last edited by
        #3

        Thanks for your reply. I tried following code in my CLeftView class on Tree item selection(OnTvnSelchanged).

        CMyPrgView* pView= (CMyPrgView*)AfxGetApp();
        if(NULL!=pView)
        {
        pView->m_Edit1.SetWindowText(L"P");
        }

        But getting "Debug Assertion Failed" error on SetWindowText().

        A 1 Reply Last reply
        0
        • M Maxim Zarus

          Thanks for your reply. I tried following code in my CLeftView class on Tree item selection(OnTvnSelchanged).

          CMyPrgView* pView= (CMyPrgView*)AfxGetApp();
          if(NULL!=pView)
          {
          pView->m_Edit1.SetWindowText(L"P");
          }

          But getting "Debug Assertion Failed" error on SetWindowText().

          A Offline
          A Offline
          Akt_4_U
          wrote on last edited by
          #4

          The AfxGetApp() will return your application class poniter not view. Here you have casted the AppClass to ViewClass poniter. This is not possible.

          akt

          M 1 Reply Last reply
          0
          • A Akt_4_U

            The AfxGetApp() will return your application class poniter not view. Here you have casted the AppClass to ViewClass poniter. This is not possible.

            akt

            M Offline
            M Offline
            Maxim Zarus
            wrote on last edited by
            #5

            I did it as suggested by "Paresh". I have also tried CMyPrgView* pView = new CMyPrgView(); but still Assertion error comes. What i do, please suggest me.

            P 1 Reply Last reply
            0
            • M Maxim Zarus

              Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #6

              You can have pointers to your view classes inside CMainFrame. and then access through AfxGetMainWnd() which will giev you pointer to CMainFrame. you have to typecast i.e. (CMainFrame*)AfxGetMainWnd(). I home it makes sense.

              Regards, Sandip.

              1 Reply Last reply
              0
              • M Maxim Zarus

                I did it as suggested by "Paresh". I have also tried CMyPrgView* pView = new CMyPrgView(); but still Assertion error comes. What i do, please suggest me.

                P Offline
                P Offline
                Paresh Chitte
                wrote on last edited by
                #7

                Please read my post carefully. Take the help of AfxGetApp[^]. Regards, Paresh.

                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