| title | CTabView Class | Microsoft Docs | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||||||||
| ms.date | 11/04/2016 | |||||||||||||
| ms.reviewer | ||||||||||||||
| ms.suite | ||||||||||||||
| ms.technology |
|
|||||||||||||
| ms.tgt_pltfrm | ||||||||||||||
| ms.topic | reference | |||||||||||||
| f1_keywords |
|
|||||||||||||
| dev_langs |
|
|||||||||||||
| helpviewer_keywords |
|
|||||||||||||
| ms.assetid | 8e6ecd9d-d28d-432b-8ec8-0446f0204d52 | |||||||||||||
| caps.latest.revision | 32 | |||||||||||||
| author | mikeblome | |||||||||||||
| ms.author | mblome | |||||||||||||
| manager | ghogen | |||||||||||||
| translation.priority.ht |
|
The CTabView class simplifies the use of the tab control class ( CMFCTabCtrl) in applications that use MFC's document/view architecture.
class CTabbedView : public CView
| Name | Description |
|---|---|
| CTabView::AddView | Adds a new view to the tab control. |
| CTabView::FindTab | Returns the index of the specified view in the tab control. |
| CTabView::GetActiveView | Returns a pointer to the currently active view |
| CTabView::GetTabControl | Returns a reference to the tab control associated with the view. |
| CTabView::RemoveView | Removes the view from the tab control. |
| CTabView::SetActiveView | Makes a view active. |
| Name | Description |
|---|---|
| CTabView::IsScrollBar | Called by the framework when creating a tab view to determine whether the tab view has a shared horizontal scroll bar. |
| CTabView::OnActivateView | Called by the framework when the tab view is made active or inactive. |
This class makes it easy to put a tabbed view into a document/view application. CTabView is a CView-derived class that contains an embedded CMFCTabCtrl object. CTabView handles all messages required to support the CMFCTabCtrl object. Simply derive a class from CTabView and plug it into your application, then add CView-derived classes by using the AddView method. The tab control will display those views as tabs.
For example, you might have a document that can be represented in different ways: as a spreadsheet, a chart, an editable form, and so on. You can create individual views drawing the data as needed, insert them into your CTabView-derived object and have them tabbed without any additional coding.
TabbedView Sample: MFC Tabbed View Application illustrates usage of CTabView.
The following example shows how CTabView is used in the TabbedView sample.
[!code-cppNVC_MFC_TabbedView#1]
Header: afxTabView.h
Adds a view to the tab control.
int AddView(
CRuntimeClass* pViewClass,
const CString& strViewLabel,
int iIndex=-1,
CCreateContext* pContext=NULL);
[in] pViewClass
A pointer to a runtime class of the inserted view.
[in] strViewLabel
Specifies the tab's text.
[in] iIndex
Specifies the zero-based position at which to insert the view. If the position is -1 the new tab is inserted at the end.
[in] pContext
A pointer to the CCreateContext of the view.
A view index if this method succeeds. Otherwise, -1.
Call this function to add a view to the tab control that is embedded in a frame.
Returns the index of the specified view in the tab control.
int FindTab(HWND hWndView) const;
[in] hWndView
The handle of the view.
The index of the view if it is found; otherwise, -1.
Call this function to retrieve the index of a view that has a specified handle.
Returns a pointer to the currently active view.
CView* GetActiveView() const;
A valid pointer to the active view, or NULL if there is no active view.
Returns a reference to the tab control associated with the view.
DECLARE_DYNCREATE CMFCTabCtrl& GetTabControl();
A reference to the tab control associated with the view.
Called by the framework when creating a tab view to determine whether the tab view has a shared horizontal scroll bar.
virtual BOOL IsScrollBar() const;
TRUE if the tab view should be created together with a shared scroll bar. Otherwise, FALSE.
The framework calls this method when a CTabView object is being created.
Override the IsScrollBar method in a CTabView-derived class and return TRUE if you want to create a view that has a shared horizontal scroll bar.
Called by the framework when the tab view is made active or inactive.
virtual void OnActivateView(CView* view);
[in] view
A pointer to the view.
The default implementation does nothing. Override this method in a CTabView-derived class to process this notification.
Removes the view from the tab control.
BOOL RemoveView(int iTabNum);
[in] iTabNum
The index of the view to remove.
The index of the removed view if this method succeeds. Otherwise -1.
Makes a view active.
BOOL SetActiveView(int iTabNum);
[in] iTabNum
The zero-based index of the tab view.
TRUE if the specified view was made active, FALSE if the view's index is invalid.
For more information see CMFCTabCtrl::SetActiveTab.