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 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