【VS开发】学习VS2010 ------ 多种类型的视图集合CTabView

多种类型的视图集合CTabView

首先利用AppWizard建立工程,然后将视类的基类更改为CTabView,并将所有的CView更改为CTabView。

依次插入以CSrollView、CListView、CFormView、CEditView为基类的CView1、CView2、CView3、CView4,并在程序中进行引用:
intCTabViewTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

         if (CTabView::OnCreate(lpCreateStruct) == -1)

                   return -1;

         // TODO:  Add yourspecialized creation code here

         AddView(RUNTIME_CLASS (CView1), _T("Scroll View"),100);

         AddView(RUNTIME_CLASS (CView2), _T("List View"),101);

         AddView(RUNTIME_CLASS (CView3), _T("Form View"),102);

         AddView(RUNTIME_CLASS (CView4), _T("Edit View"),103);

         return 0;

}

为了增强各类的显示效果,分别对加入的各个类型的视类进行程序设计。

在以CSrollView为基类的CView1中,增加CSroll相关的控制,并在OnDraw中进行图形的绘制。

在以CListView为基类的CView2中,更改List的显示风格

BOOL CView2::PreCreateWindow(CREATESTRUCT& cs)

{

         // TODO: Add your specialized code here and/or call thebase class

         cs.style|= LVS_REPORT;

         return CListView::PreCreateWindow(cs);

}

并在OnInitialUpdate()中加入列表的初始化代码:

CListCtrl& wndList = GetListCtrl ();

wndList.SetExtendedStyle (LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES);

const int nColumns = 10;

int iColumn = 0;

// Insert columns:

for (iColumn = 0;iColumn < nColumns; iColumn++)

{

         CStringstrColumn;

         strColumn.Format(_T("Column %d"), iColumn + 1);

         wndList.InsertColumn(iColumn, strColumn, LVCFMT_LEFT, 110);

}

// Insert items:

for (int i = 0; i < 10; i++)

{

         const CString strItemFmt = _T("Item (%d, %d)");

         CStringstrItem;

         strItem.Format(strItemFmt, 1, i + 1);

         int iItem = wndList.InsertItem (i, strItem, 0);

         for (iColumn = 1; iColumn < nColumns; iColumn++)

         {

                   strItem.Format(strItemFmt, iColumn + 1, i + 1);

                   wndList.SetItemText(iItem, iColumn, strItem);

         }

}

在以CFormView为基类的CView3中,加入相应的资源控件并进行程序设计,在以CEditView为基类的CView4中,加入窗体文本初始化的代码。

最终软件界面:

原文地址:https://www.cnblogs.com/huty/p/8518717.html