Single View with Multiple Tabs in MFC
-
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.
Yes. I am looking into that feature and could not get any such behavior and posted it here.
-
Yes. I am looking into that feature and could not get any such behavior and posted it here.
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.
-
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.
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.
-
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.
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?
-
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?
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.
-
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?
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.
-
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.
How to load a CView in tab which is created using CMFCTabCtrl.
-
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.
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.
-
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.
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. ?
-
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. ?
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)
-
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. ?
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!