[RESOLVED] MDI CTabView
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] MDI CTabView

Hybrid View

  1. #1
    Join Date
    Aug 2000
    Location
    Virginia, US
    Posts
    158

    [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;
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,053

    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?

  3. #3
    Join Date
    Aug 2000
    Location
    Virginia, US
    Posts
    158

    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();

  4. #4
    Join Date
    Aug 2000
    Location
    Virginia, US
    Posts
    158

    Re: MDI CTabView

    Quote Originally Posted by GCDEF View Post
    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;
    }

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,053

    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?

  6. #6
    Join Date
    Aug 2000
    Location
    Virginia, US
    Posts
    158

    Re: MDI CTabView

    Quote Originally Posted by GCDEF View Post
    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();
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center