Skip to content

Latest commit

 

History

History
218 lines (135 loc) · 6.39 KB

ctabview-class.md

File metadata and controls

218 lines (135 loc) · 6.39 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: CTabView Class
CTabView Class
11/04/2016
CTabView
AFXTABVIEW/CTabView
AFXTABVIEW/CTabView::AddView
AFXTABVIEW/CTabView::FindTab
AFXTABVIEW/CTabView::GetActiveView
AFXTABVIEW/CTabView::GetTabControl
AFXTABVIEW/CTabView::RemoveView
AFXTABVIEW/CTabView::SetActiveView
AFXTABVIEW/CTabView::IsScrollBar
AFXTABVIEW/CTabView::OnActivateView
CTabView [MFC], AddView
CTabView [MFC], FindTab
CTabView [MFC], GetActiveView
CTabView [MFC], GetTabControl
CTabView [MFC], RemoveView
CTabView [MFC], SetActiveView
CTabView [MFC], IsScrollBar
CTabView [MFC], OnActivateView
8e6ecd9d-d28d-432b-8ec8-0446f0204d52

CTabView Class

The CTabView class simplifies the use of the tab control class ( CMFCTabCtrl) in applications that use MFC's document/view architecture.

Syntax

class CTabbedView : public CView

Members

Public Methods

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.

Protected Methods

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.

Remarks

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.

Example

The following example shows how CTabView is used in the TabbedView sample.

[!code-cppNVC_MFC_TabbedView#1]

Requirements

Header: afxTabView.h

CTabView::AddView

Adds a view to the tab control.

int AddView(
    CRuntimeClass* pViewClass,
    const CString& strViewLabel,
    int iIndex=-1,
    CCreateContext* pContext=NULL);

Parameters

pViewClass
[in] A pointer to a runtime class of the inserted view.

strViewLabel
[in] Specifies the tab's text.

iIndex
[in] Specifies the zero-based position at which to insert the view. If the position is -1 the new tab is inserted at the end.

pContext
[in] A pointer to the CCreateContext of the view.

Return Value

A view index if this method succeeds. Otherwise, -1.

Remarks

Call this function to add a view to the tab control that is embedded in a frame.

CTabView::FindTab

Returns the index of the specified view in the tab control.

int FindTab(HWND hWndView) const;

Parameters

hWndView
[in] The handle of the view.

Return Value

The index of the view if it is found; otherwise, -1.

Remarks

Call this function to retrieve the index of a view that has a specified handle.

CTabView::GetActiveView

Returns a pointer to the currently active view.

CView* GetActiveView() const;

Return Value

A valid pointer to the active view, or NULL if there is no active view.

Remarks

CTabView::GetTabControl

Returns a reference to the tab control associated with the view.

DECLARE_DYNCREATE CMFCTabCtrl& GetTabControl();

Return Value

A reference to the tab control associated with the view.

CTabView::IsScrollBar

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;

Return Value

TRUE if the tab view should be created together with a shared scroll bar. Otherwise, FALSE.

Remarks

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.

CTabView::OnActivateView

Called by the framework when the tab view is made active or inactive.

virtual void OnActivateView(CView* view);

Parameters

view
[in] A pointer to the view.

Remarks

The default implementation does nothing. Override this method in a CTabView-derived class to process this notification.

CTabView::RemoveView

Removes the view from the tab control.

BOOL RemoveView(int iTabNum);

Parameters

iTabNum
[in] The index of the view to remove.

Return Value

The index of the removed view if this method succeeds. Otherwise -1.

Remarks

CTabView::SetActiveView

Makes a view active.

BOOL SetActiveView(int iTabNum);

Parameters

iTabNum
[in] The zero-based index of the tab view.

Return Value

TRUE if the specified view was made active, FALSE if the view's index is invalid.

Remarks

For more information see CMFCTabCtrl::SetActiveTab.

See also

Hierarchy Chart
Classes
CMFCTabCtrl
CView Class