|
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.
|
|
|
|
|
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.
|
|
|
|
|
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;
if (!tab.Create(CMFCTabCtrl::STYLE_FLAT, CRect(0,0,100,100), this, 1))
{
TRACE0("Failed to create output tab window\n");
return -1;
}
tab.AddTab(this, _T("tab1"),101);
tab.AddTab(this, _T("tab1"),102);
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.
modified 13-Mar-18 13:32pm.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
How to load a CView in tab which is created using CMFCTabCtrl.
|
|
|
|
|
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.
|
|
|
|
|
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. ?
|
|
|
|
|
|
Hi.
In my MFC application, i created a class which is derived from CTabView and created few tabs(views) using AddView(). Now i want to change the color of the tab views. May i know how to change the background color of those views?
Thanks in Advance.
|
|
|
|
|
|
I want the first one i.e., changing the background color of the CView. I tried with below call
SetClassLong(GetActiveView()->GetSafeHwnd(), 0, RGB(255, 0, 0)); but it dint work.
|
|
|
|
|
Sampath579 wrote: I tried with below call
SetClassLong(GetActiveView()->GetSafeHwnd(), 0, RGB(255, 0, 0)); but it dint work.
And how should it "work"? Where did you find this strange code? Did you read the SetClassLong function (Windows) documentation in MSDN?
I posted you a link to the Forum where you can find a working code. Why did you ignore it?
|
|
|
|
|
Thanks. Its working fine.
|
|
|
|
|
|
Hi.
I created a class which is derived from CTabView. In OnCretae() function it created a window with a tab control on window. Later i created few views by calling AddView(). I created 5 view.
Now, when i click on the arrow buttons on the tab control below, my control is not switching the tabs.
May i know which function should i call to switch the tabs on my window?
And also let me know how to disable it?
modified 11-Mar-18 5:13am.
|
|
|
|
|
here in the code below i am trying to print the increment every time the same object is called, but it's giving error.
#include <iostream>
using namespace std;
class Names{
int m;
static int count;
public:
void setcode(void){
m = ++count;
cout<<m<<endl;
}
};
int main(){
Names x;
for(int i=1; i<5; i++){
x.setcode();
}
return 0;
}
Error:
Quote: /tmp/ccDcxr5a.o: In function Names::setcode()': savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0xe): undefined reference toNames::count'
savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0x17): undefined reference to Names::count' savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0x1d): undefined reference toNames::count'
collect2: error: ld returned 1 exit status
Thank you
modified 10-Mar-18 7:44am.
|
|
|
|
|
Tarun Jha wrote: but it's giving error. And we must guess what that error is, and where it occurs?
|
|
|
|
|
|
You have declared the variable count in your Names class, but never defined it in your code. Add the following line after the class declaration:
int Names::count;
|
|
|
|
|
|
1>ModifyDlg.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall CModifyDlg::OnInitDialog(void)" (?OnInitDialog@CModifyDlg@@UAEHXZ)
1>WorkDlg.obj : error LNK2001: 无法解析的外部符号 "protected: virtual int __thiscall CWorkDlg::OnInitDialog(void)" (?OnInitDialog@CWorkDlg@@MAEHXZ)
|
|
|
|