mantishell 发表于 2016-7-24 21:43:41

单文档界面拆分

本帖最后由 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 = {_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;
                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);
}




stary666 发表于 2016-7-25 10:16:14

:loveliness::loveliness:
页: [1]
查看完整版本: 单文档界面拆分