你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

单文档界面拆分

[复制链接]
mantishell 提问时间:2016-7-24 21:43 /
本帖最后由 mantishell 于 2016-7-24 22:59 编辑

单文档界面的拆分,怎么做呢?
下面就总结一下。
文件不能太大,不能上传
http://yunpan.cn/c6AeRbk7nBUE7  访问密码 2290
首先在CMainFrame头文件里添加

  1. public:
  2.         CSplitterWnd m_cEventView;
复制代码
重载OnCreateClient()函数
  1. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  2. {
  3.         // TODO: Add your specialized code here and/or call the base class
  4.         if (!m_cEventView.CreateStatic (this, 2, 1))//分割成上下两个
  5.                 {
  6.                 TRACE (_T(" CMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
  7.                 return (FALSE);
  8.                 }
  9.         if (!m_cDataView.CreateStatic (&m_cEventView, 1, 2))//在上面分割的基础上,分成2个
  10.                 {
  11.                 TRACE (_T("CMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
  12.                 return (FALSE);
  13.                 }
  14.         RECT rc;
  15.         GetClientRect (&rc);

  16.         // Create "view" in top left pane:
  17.         if (!m_cDataView.CreateView (
  18.                 0, 0,
  19.                 RUNTIME_CLASS (CItemView),
  20.                 CSize (rc.right / 2, 3 * rc.bottom / 4),
  21.                 pContext))
  22.                 {
  23.                 ASSERT (FALSE);
  24.                 return (FALSE);
  25.                 }

  26.         if (!m_cDataView.CreateView (
  27.                 0, 1,
  28.                 RUNTIME_CLASS (CItemView),
  29.                 CSize (rc.right / 2, 3 * rc.bottom / 4),
  30.                 pContext))
  31.                 {
  32.                 ASSERT (FALSE);
  33.                 return (FALSE);
  34.                 }
  35.         if (!m_cEventView.CreateView (
  36.                 1, 0,
  37.                 RUNTIME_CLASS (CItemView),//CItemView是创建的基于CListView的类
  38.                 CSize (rc.right, rc.bottom / 4),
  39.                 pContext))
  40.                 {
  41.                 ASSERT (FALSE);
  42.                 return (FALSE);
  43.                 }
  44.         return true;//这句一定要加
  45.         //return CFrameWnd::OnCreateClient(lpcs, pContext);//这里注意
  46. }
复制代码
在派生的类头文件
  1. CListCtrl m_cListCtrl;
  2.         CImageList m_cImageList;
复制代码
源文件里

  1. <div>
  2. BOOL CItemView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  3. {
  4.         // TODO: Add your specialized code here and/or call the base class

  5.         if (!CWnd::Create (lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
  6.                 return (FALSE);//这句一定要添加,不然GetListCtrl ()无法使用。

  7.         m_cImageList.Create (IDB_ITEMIMAGES, 14, 2, RGB (255, 0, 255));
  8.         m_cImageList.SetBkColor (CLR_NONE);
  9.         GetListCtrl ().SetImageList (&m_cImageList, LVSIL_SMALL);

  10.         CListCtrl& listCtrl = GetListCtrl();
  11.         //listCtrl.SetImageList(&m_cImageList,LVSIL_NORMAL);
  12.         //listCtrl.SetImageList(&m_ImageListSmall,LVSIL_SMALL);
  13.         LV_COLUMN listCol;
  14.         wchar_t* const arCols[6] = {_T("序号"),_T("姓名"),_T("学号"),_T("成绩1"),_T("成绩2"),_T("成绩3")};
  15.         listCol.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
  16.         // 添加表头
  17.         for(int nCol=0;nCol<6;nCol++)
  18.         {
  19.                 listCol.iSubItem = nCol;
  20.                 listCol.pszText = arCols[nCol];
  21.                 listCol.fmt = LVCFMT_LEFT;
  22.                 listCtrl.InsertColumn(nCol,&listCol);
  23.         }


  24.    int        nIndex,nItem;
  25.         CString strDisplay;
  26.         for(nItem=0;nItem<12;nItem++)
  27.         {
  28.                 strDisplay.Format(_T("%d"),nItem);
  29.                 nIndex = listCtrl.InsertItem(nItem,strDisplay);
  30.                 listCtrl.SetItemText(nIndex,1,_T("张三"));
  31.                 listCtrl.SetItemText(nIndex,2,_T("D301"));
  32.                 listCtrl.SetItemText(nIndex,3,_T("0"));
  33.                 listCtrl.SetItemText(nIndex,4,_T("D3115"));
  34.                 listCtrl.SetItemText(nIndex,5,_T("0"));
  35.         }
  36.          LONG lStyle;
  37.       lStyle = GetWindowLong(listCtrl.m_hWnd, GWL_STYLE);//获取当前窗口style
  38.       lStyle &= ~LVS_TYPEMASK; //清除显示方式位
  39.       lStyle |= LVS_REPORT; //设置style设置为报表方式
  40.       SetWindowLong(listCtrl.m_hWnd, GWL_STYLE, lStyle);//设置style

  41.         listCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  42.         listCtrl.SetColumnWidth(0,LVSCW_AUTOSIZE);
  43.         listCtrl.SetColumnWidth(1,100);
  44.         listCtrl.SetColumnWidth(2,100);
  45.         listCtrl.SetColumnWidth(3,100);
  46.         listCtrl.SetColumnWidth(4,100);
  47.         listCtrl.SetColumnWidth(5,100);
  48.         return (TRUE);//这句必须有
  49.         //return CListView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  50. }
复制代码




7.png
6.png
5.png
4.png
3.png
2.png
1.png
收藏 评论1 发布时间:2016-7-24 21:43

举报

1个回答
stary666 回答时间:2016-7-25 10:16:14

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版