-
November 7th, 2013, 09:50 AM
#1
[RESOLVED] MDI CTabView
I have an MDI app with a CTabView that has 3 CView's (CView1, CView2, CView3) added as individual tabs...
Code:
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_TABBEDTYPE,
RUNTIME_CLASS(CTabbedViewDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMyTabView));
AddDocTemplate(pDocTemplate);
I want to get a pointer to CMyTabView. I use the following code from MSDN (Accessing a view from anywhere) in an attempt to access CMyTabView but GetActiveView only gets the CView1.
How can I get a pointer to CMyTabView?
Code:
CMyTabView* CMyTabView::GetView()
{
CMDIChildWnd * pChild = ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();
if (!pChild )
return NULL;
CView* pView = pChild->GetActiveView();
if(!pView )
return NULL;
// Fail if view is of wrong kind
if(!pView->IsKindOf(RUNTIME_CLASS(CMyTabView) ) )
return NULL;
return (CMyTabView*) pView;
}
-
November 7th, 2013, 09:57 AM
#2
Re: MDI CTabView
Just guessing, but I would think your CMyTabView is the parent of View1, so try pView->GetParent();
If it's a member of CMyTabView though, how are you calling it without a pointer to your tab view?
-
November 7th, 2013, 10:14 AM
#3
Re: MDI CTabView
CView1, CView2... are not members of CMyTabView, they are added as tabs with...
Code:
int CMyTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabView::OnCreate(lpCreateStruct) == -1)
return -1;
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100);
AddView (RUNTIME_CLASS (CView2), _T("Pair"), 101);
AddView (RUNTIME_CLASS (CView3), _T("Data"), 102);
return 0;
}
I tried GetParent casting it to CMyTabView but it gives a pointer to the "CMFCTabCtrl"
CView* pView2 = (CMyTabView*)pView->GetParent();
-
November 7th, 2013, 12:01 PM
#4
Re: MDI CTabView
Okay, but since your function is a member of CMyTabView and you want to get a pointer to your CMyTabView object, how are you able to call the function, since in theory, you don't have a pointer to that object?
-
November 7th, 2013, 12:27 PM
#5
Re: MDI CTabView
Originally Posted by GCDEF
Okay, but since your function is a member of CMyTabView and you want to get a pointer to your CMyTabView object, how are you able to call the function, since in theory, you don't have a pointer to that object?
Hmm, good point. I'm using a static function in CMyTabView...
Code:
class CMyTabView : public CTabView
{
public:
...
...
virtual void OnInitialUpdate();
CSimpleMap<int, CView*> m_viewMap;
CView* GetView(int nView);
afx_msg void OnDestroy();
static CMyTabView* GetView();
};
-
November 7th, 2013, 11:19 PM
#6
Re: MDI CTabView
Originally Posted by GCDEF
Just guessing, but I would think your CMyTabView is the parent of View1, so try pView->GetParent();
If it's a member of CMyTabView though, how are you calling it without a pointer to your tab view?
You were right get the CView1's parent which is the CMFCTabCtrl and then get the CMFCTabCtrl's parent which is the CTabView. Solved.
Code:
CMyTabView* CMyTabView::GetView()
{
CMDIChildWnd * pChild = ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();
if (!pChild )
return NULL;
CView* pChildView = pChild->GetActiveView();
CMFCTabCtrl* pCtrl = (CMFCTabCtrl*)pChildView->GetParent();
CMyTabView* pView = (CMyTabView*)pCtrl->GetParent();
if(!pView )
return NULL;
// Fail if view is of wrong kind
if(!pView->IsKindOf(RUNTIME_CLASS(CMyTabView) ) )
return NULL;
return (CMyTabView*) pView;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|