How to reuse a single CView class with multiple tabs in MFC
-
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?
-
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?
-
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?
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 ?
-
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?
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 ...
-
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 ...
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.
-
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.
-
"only one view object should be available and multiple tabs should exists" If you need just one view, why you need tabs then ?
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.
-
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.
-
Then you should simulate tabs with some simple buttons, which will change the CYourView content ...
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[^]