在线时间42 小时
UID2081656
ST金币0
蝴蝶豆0
注册时间2014-3-26
中级会员
- 最后登录
- 1970-1-1
|
a0a.1 32b0c
本帖最后由 mantishell 于 2016-7-24 22:59 编辑
单文档界面的拆分,怎么做呢?
下面就总结一下。
文件不能太大,不能上传
http://yunpan.cn/c6AeRbk7nBUE7 访问密码 2290
首先在CMainFrame头文件里添加
- public:
- CSplitterWnd m_cEventView;
复制代码 重载OnCreateClient()函数
- BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- if (!m_cEventView.CreateStatic (this, 2, 1))//分割成上下两个
- {
- TRACE (_T(" CMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
- return (FALSE);
- }
- if (!m_cDataView.CreateStatic (&m_cEventView, 1, 2))//在上面分割的基础上,分成2个
- {
- TRACE (_T("CMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
- return (FALSE);
- }
- RECT rc;
- GetClientRect (&rc);
- // Create "view" in top left pane:
- if (!m_cDataView.CreateView (
- 0, 0,
- RUNTIME_CLASS (CItemView),
- CSize (rc.right / 2, 3 * rc.bottom / 4),
- pContext))
- {
- ASSERT (FALSE);
- return (FALSE);
- }
- if (!m_cDataView.CreateView (
- 0, 1,
- RUNTIME_CLASS (CItemView),
- CSize (rc.right / 2, 3 * rc.bottom / 4),
- pContext))
- {
- ASSERT (FALSE);
- return (FALSE);
- }
- if (!m_cEventView.CreateView (
- 1, 0,
- RUNTIME_CLASS (CItemView),//CItemView是创建的基于CListView的类
- CSize (rc.right, rc.bottom / 4),
- pContext))
- {
- ASSERT (FALSE);
- return (FALSE);
- }
- return true;//这句一定要加
- //return CFrameWnd::OnCreateClient(lpcs, pContext);//这里注意
- }
复制代码 在派生的类头文件
- CListCtrl m_cListCtrl;
- CImageList m_cImageList;
复制代码 源文件里
- <div>
- BOOL CItemView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- if (!CWnd::Create (lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
- return (FALSE);//这句一定要添加,不然GetListCtrl ()无法使用。
- m_cImageList.Create (IDB_ITEMIMAGES, 14, 2, RGB (255, 0, 255));
- m_cImageList.SetBkColor (CLR_NONE);
- GetListCtrl ().SetImageList (&m_cImageList, LVSIL_SMALL);
- CListCtrl& listCtrl = GetListCtrl();
- //listCtrl.SetImageList(&m_cImageList,LVSIL_NORMAL);
- //listCtrl.SetImageList(&m_ImageListSmall,LVSIL_SMALL);
- LV_COLUMN listCol;
- wchar_t* const arCols[6] = {_T("序号"),_T("姓名"),_T("学号"),_T("成绩1"),_T("成绩2"),_T("成绩3")};
- listCol.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
- // 添加表头
- for(int nCol=0;nCol<6;nCol++)
- {
- listCol.iSubItem = nCol;
- listCol.pszText = arCols[nCol];
- listCol.fmt = LVCFMT_LEFT;
- listCtrl.InsertColumn(nCol,&listCol);
- }
- int nIndex,nItem;
- CString strDisplay;
- for(nItem=0;nItem<12;nItem++)
- {
- strDisplay.Format(_T("%d"),nItem);
- nIndex = listCtrl.InsertItem(nItem,strDisplay);
- listCtrl.SetItemText(nIndex,1,_T("张三"));
- listCtrl.SetItemText(nIndex,2,_T("D301"));
- listCtrl.SetItemText(nIndex,3,_T("0"));
- listCtrl.SetItemText(nIndex,4,_T("D3115"));
- listCtrl.SetItemText(nIndex,5,_T("0"));
- }
- LONG lStyle;
- lStyle = GetWindowLong(listCtrl.m_hWnd, GWL_STYLE);//获取当前窗口style
- lStyle &= ~LVS_TYPEMASK; //清除显示方式位
- lStyle |= LVS_REPORT; //设置style设置为报表方式
- SetWindowLong(listCtrl.m_hWnd, GWL_STYLE, lStyle);//设置style
- listCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- listCtrl.SetColumnWidth(0,LVSCW_AUTOSIZE);
- listCtrl.SetColumnWidth(1,100);
- listCtrl.SetColumnWidth(2,100);
- listCtrl.SetColumnWidth(3,100);
- listCtrl.SetColumnWidth(4,100);
- listCtrl.SetColumnWidth(5,100);
- return (TRUE);//这句必须有
- //return CListView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
复制代码
|
|