自定义的view类用于显示在对话框上
class CGroupMenuView : public CScrollView
{
protected:
CGroupMenuView();
………………
…………
};
class CWorkView : public CScrollView
{
protected:
CWorkView();
…………
…………
};
//创建左视图 { CCreateContext cx; cx.m_pNewViewClass = RUNTIME_CLASS( CGroupMenuView ) ; cx.m_pCurrentDoc = NULL; CFrameWnd* pfWnd = (CFrameWnd*)this; m_pLeftView = (CGroupMenuView*)pfWnd->CreateView( &cx ); m_pLeftView->SetScrollSizes( MM_TEXT, CSize(100, 100) );//当你继承的基类是滚动视图类时这句很重要,需要设置视的大小 m_pLeftView->SetParent( this ); m_pLeftView->InitView(); } //创建右视图 { CCreateContext cx; cx.m_pNewViewClass = RUNTIME_CLASS( CWorkView ) ; cx.m_pCurrentDoc = NULL; CFrameWnd* pfWnd = (CFrameWnd*)this; m_pRightView = (CWorkView*)pfWnd->CreateView( &cx ); m_pRightView->SetScrollSizes( MM_TEXT, CSize(100, 100) );//当你继承的基类是滚动视图类时这句很重要,需要设置视的大小 m_pRightView->SetParent( this ); }
在视图区添加ListCtrl控件
void CListzzzView::OnInitialUpdate() { CListView::OnInitialUpdate(); CListCtrl& ctl=GetListCtrl(); // TODO: Add your specialized code here and/or call the base class //设置列表控件风格 DWORD dwStyle=::GetWindowLong(m_hWnd,GWL_STYLE); dwStyle|=LVS_REPORT|LVS_SHOWSELALWAYS|LVS_EDITLABELS; ::SetWindowLong(m_hWnd,GWL_STYLE,dwStyle); dwStyle=ctl.GetExtendedStyle(); dwStyle|= LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT; //设置扩展风格 ctl.SetExtendedStyle(dwStyle); //列表控件头内容 TCHAR tittle[3][10] = {_T("姓名"),_T("单位"),_T("地址")}; LV_COLUMN lvcolumn; CRect rect; GetWindowRect(&rect); //填充列表控件头 for(int i=0;i<3;i++) { lvcolumn.mask =LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT |LVCF_WIDTH|LVCF_ORDER; lvcolumn.fmt = LVCFMT_LEFT; lvcolumn.pszText = tittle[i]; lvcolumn.iSubItem = i; lvcolumn.iOrder = i; lvcolumn.cx = rect.Height()/3; GetListCtrl().InsertColumn(i, &lvcolumn); } }