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. Single View with Multiple Tabs in MFC

Single View with Multiple Tabs in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancequestion
19 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

    Hi I have a requirement where i need to display few tabs and render something in only one view instead of creating multiple views for each tab. The reason is i am loading an active x control on that view. So, i written class which inherits from CTabView, but When i call AddView(), each AddView() is creating a new object and i need to load active x control on each view which is violating my requirement and unnecessary memory is getting created. Is there is any way to create only one view for all the tabs, such that i can create only one view and load active x control on that view and switch the tabs to render different things on one view.? Currently i am trying with tabbedpane assuming my above requirement will get solved. Please let me know incase if there is any other option?

    L 1 Reply Last reply
    0
    • S Sampath579

      Hi I have a requirement where i need to display few tabs and render something in only one view instead of creating multiple views for each tab. The reason is i am loading an active x control on that view. So, i written class which inherits from CTabView, but When i call AddView(), each AddView() is creating a new object and i need to load active x control on each view which is violating my requirement and unnecessary memory is getting created. Is there is any way to create only one view for all the tabs, such that i can create only one view and load active x control on that view and switch the tabs to render different things on one view.? Currently i am trying with tabbedpane assuming my above requirement will get solved. Please let me know incase if there is any other option?

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

      Why do you need multiple tabs in the first place? It sounds like you just want your view to render different data based on some external setting or user selection.

      S 1 Reply Last reply
      0
      • L Lost User

        Why do you need multiple tabs in the first place? It sounds like you just want your view to render different data based on some external setting or user selection.

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

        I have some drawings to display. For Eg: I have a drawing file which internally contains 5 sub drawings in it. So based on no. of sub drawings, i have to create 5 tabs. In each tab each sub drawing should get render. But user is allowed to view only one sub drawing at a time i.e., the active tab drawing. Thats the reason why i need to create tabs. When i click on first tab, first sub drawing will be displayed. if second tab is selected then second sub drawing should be displayed. like wise rest of the drawing when user selects the tab.

        L 1 Reply Last reply
        0
        • S Sampath579

          I have some drawings to display. For Eg: I have a drawing file which internally contains 5 sub drawings in it. So based on no. of sub drawings, i have to create 5 tabs. In each tab each sub drawing should get render. But user is allowed to view only one sub drawing at a time i.e., the active tab drawing. Thats the reason why i need to create tabs. When i click on first tab, first sub drawing will be displayed. if second tab is selected then second sub drawing should be displayed. like wise rest of the drawing when user selects the tab.

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

          According to your original question your requirement is to have only a single View, so you do not need multiple tabs. You just need to render the appropriate drawing when the user makes a choice.

          S 1 Reply Last reply
          0
          • L Lost User

            According to your original question your requirement is to have only a single View, so you do not need multiple tabs. You just need to render the appropriate drawing when the user makes a choice.

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

            Yes exactly. I need only one view. But the User interaction should be on tabs. To be more precise, i need the UI in the form of tabs but the view should be only one. But when i call Addview(), each time a new view is getting created.

            L 1 Reply Last reply
            0
            • S Sampath579

              Yes exactly. I need only one view. But the User interaction should be on tabs. To be more precise, i need the UI in the form of tabs but the view should be only one. But when i call Addview(), each time a new view is getting created.

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

              Sampath579 wrote:

              But when i call Addview(), each time a new view is getting created.

              You need to show your code; it is difficult to guess what you are doing.

              S 1 Reply Last reply
              0
              • L Lost User

                Sampath579 wrote:

                But when i call Addview(), each time a new view is getting created.

                You need to show your code; it is difficult to guess what you are doing.

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

                class MyMainClass : public CTabView
                {
                int OnCreate(LPCREATESTRUCT lpCreateStruct);
                };

                int MyMainClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
                {
                if (CTabView::OnCreate(lpCreateStruct) == -1)
                return -1;

                     AddView(RUNTIME\_CLASS(CDrawingView), \_T("Tab1"));
                 AddView(RUNTIME\_CLASS(CDrawingView), \_T("Tab2"));
                

                }

                class CDrawingView : public CScrollView
                {
                /.... rendering logic.
                }

                So, each time i call AddView() the CDrawingView class is getting instantiated and new view is getting created. Instead only one view should be available and new tabs should get created.

                L 1 Reply Last reply
                0
                • S Sampath579

                  class MyMainClass : public CTabView
                  {
                  int OnCreate(LPCREATESTRUCT lpCreateStruct);
                  };

                  int MyMainClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
                  {
                  if (CTabView::OnCreate(lpCreateStruct) == -1)
                  return -1;

                       AddView(RUNTIME\_CLASS(CDrawingView), \_T("Tab1"));
                   AddView(RUNTIME\_CLASS(CDrawingView), \_T("Tab2"));
                  

                  }

                  class CDrawingView : public CScrollView
                  {
                  /.... rendering logic.
                  }

                  So, each time i call AddView() the CDrawingView class is getting instantiated and new view is getting created. Instead only one view should be available and new tabs should get created.

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

                  The whole point of using AddView is to add a new View to the tab group. The documentation (CTabView::AddView[^]) makes it clear that it creates a new View for each call. If you want a single View then you will need to find an alternative to the CTabView control.

                  S 1 Reply Last reply
                  0
                  • L Lost User

                    The whole point of using AddView is to add a new View to the tab group. The documentation (CTabView::AddView[^]) makes it clear that it creates a new View for each call. If you want a single View then you will need to find an alternative to the CTabView control.

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

                    Yes. I am looking into that feature and could not get any such behavior and posted it here.

                    V 1 Reply Last reply
                    0
                    • S Sampath579

                      Yes. I am looking into that feature and could not get any such behavior and posted it here.

                      V Offline
                      V Offline
                      Victor Nijegorodov
                      wrote on last edited by
                      #10

                      Then don't call AddView! Instead try to operate the CMFCTabCtrl class (or some of its base ones) to add/remove/change tabs and "on-change-tab" just display the only one view you have.

                      S 4 Replies Last reply
                      0
                      • V Victor Nijegorodov

                        Then don't call AddView! Instead try to operate the CMFCTabCtrl class (or some of its base ones) to add/remove/change tabs and "on-change-tab" just display the only one view you have.

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

                        ok. How can it solve my problem.

                        class MyMainClass : public CScrollView
                        {
                        int OnCreate(LPCREATESTRUCT lpCreateStruct);
                        }

                        int MyMainClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
                        {
                        if (CScrollView::OnCreate(lpCreateStruct) == -1)
                        return -1;

                        //CRect rect;
                        //GetWindowRect(rect);
                        if (!tab.Create(CMFCTabCtrl::STYLE\_FLAT, CRect(0,0,100,100), this, 1))
                        {
                        	TRACE0("Failed to create output tab window\\n");
                        	return -1;      // fail to create
                        }
                        tab.AddTab(this, \_T("tab1"),101);
                        tab.AddTab(this, \_T("tab1"),102);
                        // TODO:  Add your specialized creation code here
                        
                        return 0;
                        

                        }

                        Above piece of code created a tabcontrol with 2 tabs on it. But with out some view on this window how can i render some thing. sorry if i miss anything to create view. Do i need to inherit my class from CMFCtabCtrl or is it ok even if i inherit from CScrollView? Also when i select the second tab, my application is getting hanged. What could be the reason? Edit 2: I have gone through some examples and understood that, "this" in below call created issues.

                        tab.AddTab(this, _T("tab1"),101)

                        instead of this, we need to provide the control we are going to add to that tab control. For eg; CEdit edit; we need to give &edit instead of this. I saw this in microsoft samples. This also does not solve my problem. In case if i have 3 tabs, then i need to create 3 CViews and add them to tabcontrol. Again this is like kind of creating new view for each tab. But i want only one view and different tabs.

                        V 1 Reply Last reply
                        0
                        • S Sampath579

                          ok. How can it solve my problem.

                          class MyMainClass : public CScrollView
                          {
                          int OnCreate(LPCREATESTRUCT lpCreateStruct);
                          }

                          int MyMainClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
                          {
                          if (CScrollView::OnCreate(lpCreateStruct) == -1)
                          return -1;

                          //CRect rect;
                          //GetWindowRect(rect);
                          if (!tab.Create(CMFCTabCtrl::STYLE\_FLAT, CRect(0,0,100,100), this, 1))
                          {
                          	TRACE0("Failed to create output tab window\\n");
                          	return -1;      // fail to create
                          }
                          tab.AddTab(this, \_T("tab1"),101);
                          tab.AddTab(this, \_T("tab1"),102);
                          // TODO:  Add your specialized creation code here
                          
                          return 0;
                          

                          }

                          Above piece of code created a tabcontrol with 2 tabs on it. But with out some view on this window how can i render some thing. sorry if i miss anything to create view. Do i need to inherit my class from CMFCtabCtrl or is it ok even if i inherit from CScrollView? Also when i select the second tab, my application is getting hanged. What could be the reason? Edit 2: I have gone through some examples and understood that, "this" in below call created issues.

                          tab.AddTab(this, _T("tab1"),101)

                          instead of this, we need to provide the control we are going to add to that tab control. For eg; CEdit edit; we need to give &edit instead of this. I saw this in microsoft samples. This also does not solve my problem. In case if i have 3 tabs, then i need to create 3 CViews and add them to tabcontrol. Again this is like kind of creating new view for each tab. But i want only one view and different tabs.

                          V Offline
                          V Offline
                          Victor Nijegorodov
                          wrote on last edited by
                          #12

                          Sampath579 wrote:

                          I have gone through some examples and understood that, "this" in below call created issues.

                          tab.AddTab(this, _T("tab1"),101)

                          instead of this, we need to provide the control we are going to add to that tab control

                          Did you try to provide the same View for all created tabs?

                          S 2 Replies Last reply
                          0
                          • V Victor Nijegorodov

                            Sampath579 wrote:

                            I have gone through some examples and understood that, "this" in below call created issues.

                            tab.AddTab(this, _T("tab1"),101)

                            instead of this, we need to provide the control we are going to add to that tab control

                            Did you try to provide the same View for all created tabs?

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

                            I tried with CEdit as per the example in msdn. But instead of CEdit i need CView. If i declare CView m_windView; //throwing error since it contains virtual functions and we need to implement them.

                            1 Reply Last reply
                            0
                            • V Victor Nijegorodov

                              Sampath579 wrote:

                              I have gone through some examples and understood that, "this" in below call created issues.

                              tab.AddTab(this, _T("tab1"),101)

                              instead of this, we need to provide the control we are going to add to that tab control

                              Did you try to provide the same View for all created tabs?

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

                              Which class should i take in order to display my drawings in the view. I tried with CView and CScrollView. Both the classes contains virtual functions and it showing error. I need a view where mouse down , mouse up, mouse wheel should work on it. Any suggestions please.

                              1 Reply Last reply
                              0
                              • V Victor Nijegorodov

                                Then don't call AddView! Instead try to operate the CMFCTabCtrl class (or some of its base ones) to add/remove/change tabs and "on-change-tab" just display the only one view you have.

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

                                How to load a CView in tab which is created using CMFCTabCtrl.

                                1 Reply Last reply
                                0
                                • V Victor Nijegorodov

                                  Then don't call AddView! Instead try to operate the CMFCTabCtrl class (or some of its base ones) to add/remove/change tabs and "on-change-tab" just display the only one view you have.

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

                                  Then i created CMFCTabCtl and created a tab control. Next, how to add a CView to tabs? I saw samples like how to add a CEdit control to tab but dint get any clue on how to add CView to tabs? If i can add a Cview to tabs then my problem would be solved. I can add same CView to all the tabs and finally i will end up with one view and mutliple tabs which is my requirement.

                                  1 Reply Last reply
                                  0
                                  • V Victor Nijegorodov

                                    Then don't call AddView! Instead try to operate the CMFCTabCtrl class (or some of its base ones) to add/remove/change tabs and "on-change-tab" just display the only one view you have.

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

                                    Victor, May i know how can know whether user selected different tabs? I mean my function should know when user selects different tabs, based on that i can refresh my single view. ?

                                    V 2 Replies Last reply
                                    0
                                    • S Sampath579

                                      Victor, May i know how can know whether user selected different tabs? I mean my function should know when user selects different tabs, based on that i can refresh my single view. ?

                                      V Offline
                                      V Offline
                                      Victor Nijegorodov
                                      wrote on last edited by
                                      #18

                                      Have a look at this discussion: [visual c++ - CMFCTabCtrl catch tab change event - Stack Overflow](https://stackoverflow.com/questions/17739054/cmfctabctrl-catch-tab-change-event)

                                      1 Reply Last reply
                                      0
                                      • S Sampath579

                                        Victor, May i know how can know whether user selected different tabs? I mean my function should know when user selects different tabs, based on that i can refresh my single view. ?

                                        V Offline
                                        V Offline
                                        Victor Nijegorodov
                                        wrote on last edited by
                                        #19

                                        Did you try to google for something like "CMFCTabCtrl handle tab change"? Try! Then you'll find this one: [visual c++ - CMFCTabCtrl catch tab change event - Stack Overflow](https://stackoverflow.com/questions/17739054/cmfctabctrl-catch-tab-change-event) and some more info!

                                        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