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. How to reuse a single CView class with multiple tabs in MFC

How to reuse a single CView class with multiple tabs in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
9 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.
  • S Offline
    S Offline
    Sampath579
    wrote on last edited by
    #1

    I created a class which inherits from CTabView as follows:

    class CTabClass : public CTabView
    {

        void OnCreate()
        {
          m\_CView = RUNTIME\_CLASS(CDocumentView);
          AddView(m\_CView,\_T("Tab1"));
          AddView(m\_CView,\_T("Tab2")); //this creating 2nd tab but throwing assertions and 
                                           //finally crashing while accessing it.	
        }
    

    }

    I want only one view for all the tabs. Is it possible in MFC?

    L _ 3 Replies Last reply
    0
    • S Sampath579

      I created a class which inherits from CTabView as follows:

      class CTabClass : public CTabView
      {

          void OnCreate()
          {
            m\_CView = RUNTIME\_CLASS(CDocumentView);
            AddView(m\_CView,\_T("Tab1"));
            AddView(m\_CView,\_T("Tab2")); //this creating 2nd tab but throwing assertions and 
                                             //finally crashing while accessing it.	
          }
      

      }

      I want only one view for all the tabs. Is it possible in MFC?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      How many more times do you plan to repost this question? We have explained why this will not do what you want, and given some suggestions for finding an alternative approach. Please try some of those suggestions for yourself.

      1 Reply Last reply
      0
      • S Sampath579

        I created a class which inherits from CTabView as follows:

        class CTabClass : public CTabView
        {

            void OnCreate()
            {
              m\_CView = RUNTIME\_CLASS(CDocumentView);
              AddView(m\_CView,\_T("Tab1"));
              AddView(m\_CView,\_T("Tab2")); //this creating 2nd tab but throwing assertions and 
                                               //finally crashing while accessing it.	
            }
        

        }

        I want only one view for all the tabs. Is it possible in MFC?

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Yes, it could work, but not like you tried above ... think that m_CView is the same CView instance on every tab, which is impossible ... but you can try to create a new instance on every AddView call, something like that:

              AddView(new CYourView(),\_T("Tab1"));
              AddView(new CYourView(),\_T("Tab2")); 
        

        this is simplistic approach, that I wrote it just you see the point, but in a real situation, you have to elaborate this: create any instance of CYourView object you need, add every one of them in an array of pointers, and supply this pointers on AddView call as first argument. Do you understand what I say ?

        1 Reply Last reply
        0
        • S Sampath579

          I created a class which inherits from CTabView as follows:

          class CTabClass : public CTabView
          {

              void OnCreate()
              {
                m\_CView = RUNTIME\_CLASS(CDocumentView);
                AddView(m\_CView,\_T("Tab1"));
                AddView(m\_CView,\_T("Tab2")); //this creating 2nd tab but throwing assertions and 
                                                 //finally crashing while accessing it.	
              }
          

          }

          I want only one view for all the tabs. Is it possible in MFC?

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          And the solution that I just give you is more as you see why your approach is not working than to be applied in your application ... because the creation of your CYourView is not that simple ... they must be attached at you CDocument, and so on ... Because you have problems in completing your task, this reveal that your approach is not right ... you have to think to another ...

          S 1 Reply Last reply
          0
          • _ _Flaviu

            And the solution that I just give you is more as you see why your approach is not working than to be applied in your application ... because the creation of your CYourView is not that simple ... they must be attached at you CDocument, and so on ... Because you have problems in completing your task, this reveal that your approach is not right ... you have to think to another ...

            S Offline
            S Offline
            Sampath579
            wrote on last edited by
            #5

            I can create different views successfully if i create objects for each individual view as you said AddView(new MyView(),_T("tab1")); AddView(new MyView(),_T("tab2")); But my requirement is not create multiple view objects, only one view object should be available and multiple tabs should exists. The single view should keep on refreshing when tabs are changed.

            _ 1 Reply Last reply
            0
            • S Sampath579

              I can create different views successfully if i create objects for each individual view as you said AddView(new MyView(),_T("tab1")); AddView(new MyView(),_T("tab2")); But my requirement is not create multiple view objects, only one view object should be available and multiple tabs should exists. The single view should keep on refreshing when tabs are changed.

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              "only one view object should be available and multiple tabs should exists" If you need just one view, why you need tabs then ?

              S 1 Reply Last reply
              0
              • _ _Flaviu

                "only one view object should be available and multiple tabs should exists" If you need just one view, why you need tabs then ?

                S Offline
                S Offline
                Sampath579
                wrote on last edited by
                #7

                Based on user selection, the graphics on the CView should change. On this CView i will load some Active X control to render the graphics on this window. If i create multiple CViews with new object, then i have to load the Active X Control on each CView which is a costly operation and memory increases and it not a good way to deal as there are many issues with memory, performance and other areas in my application. Thats why i want multiple tabs with one single view to solve my issue.

                _ 1 Reply Last reply
                0
                • S Sampath579

                  Based on user selection, the graphics on the CView should change. On this CView i will load some Active X control to render the graphics on this window. If i create multiple CViews with new object, then i have to load the Active X Control on each CView which is a costly operation and memory increases and it not a good way to deal as there are many issues with memory, performance and other areas in my application. Thats why i want multiple tabs with one single view to solve my issue.

                  _ Offline
                  _ Offline
                  _Flaviu
                  wrote on last edited by
                  #8

                  Then you should simulate tabs with some simple buttons, which will change the CYourView content ...

                  S 1 Reply Last reply
                  0
                  • _ _Flaviu

                    Then you should simulate tabs with some simple buttons, which will change the CYourView content ...

                    S Offline
                    S Offline
                    Sampath579
                    wrote on last edited by
                    #9

                    Yes. Corrently i am working on this idea. But facing some problem as mentioned in below link. Can we include two Message Maps in one class? - C / C++ / MFC Discussion Boards[^]

                    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