乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      單文檔多視圖

       牛人的尾巴 2017-01-03
      2014-06-10 21:28 3926人閱讀 評論(0) 收藏 舉報
      分類:

      目錄(?)[+]

      最后界面


      1、創(chuàng)建單文檔exe,支持切分窗口。

      2、新建對話框資源


      ID為IDD_TREEVIEW,Style=CHILD,BORDER=NONE,

      刪掉按鈕OK和CANCEL,添加Tree控件IDC_TREE,占滿整個對話框


      導(dǎo)入位圖資源,ID為IDB_BITMAP


      新建列表對話框IDD_LISTCTRLVIEW,Style=CHILD,BORDER=NONE,

      添加LISTCONTROL控件IDC_LIST,占滿藍色邊框,


      和編輯視圖的對話框資源IDD_EDITVIEW,Style=CHILD,BORDER=NONE,刪掉上面的按鈕。

      添加EditBox控件IDC_EDIT,占滿藍色邊界線


      3、新建視圖類并添加控件型變量和初始化函數(shù)

      建立2 個View 的類,這里我們讓這2個View 的類繼承于FormView,
       CListControlView 繼承于FormView 關(guān)聯(lián)對話框 IDD_LISTVIEW,為了后面可以new 將構(gòu)造函數(shù)改為publlic屬性(默認為protected)

      1. class CListControlView : public CFormView  
      2.  {  
      3.  public:  
      4.     CListControlView();           // protected constructor used by dynamic creation  
      5.     DECLARE_DYNCREATE(CListControlView)  
      1. };  
      為列邊框添加控件類型變量m_listCtrl

      為對話框添加OnSize消息,使列表框與對話框等大

      [html] view plaincopy
      1. void CListControlView::OnSize(UINT nType, int cx, int cy)   
      2.  {  
      3.     CFormView::OnSize(nType, cx, cy);  
      4.       
      5.     // TODO: Add your message handler code here  
      6.     CFormView::ShowScrollBar(SB_VERT,FALSE);  
      7.     CFormView::ShowScrollBar(SB_HORZ,FALSE);  
      8.     if (GetSafeHwnd())  
      9.     {  
      10.         if (m_listCtrl.GetSafeHwnd())  
      11.         {  
      12.             CRect rect(0,0,cx,cy);  
      13.             m_listCtrl.MoveWindow(&rect);  
      14.         }  
      15.     }         
      16.  }  

      添加虛函數(shù),初始化列表框

      1. void CListControlView::OnInitialUpdate()   
      2.  {  
      3.     CFormView::OnInitialUpdate();  
      4.       
      5.     // TODO: Add your specialized code here and/or call the base class  
      6.     CRect rect;  
      7.     m_listCtrl.GetClientRect(&rect);  
      8.       
      9.     m_listCtrl.InsertColumn(0, "From", LVCFMT_LEFT, rect.Width()/4);  
      10.     m_listCtrl.InsertColumn(1, "Subject", LVCFMT_LEFT, rect.Width()/4);  
      11.     m_listCtrl.InsertColumn(2, "Date", LVCFMT_LEFT, rect.Width()/4);  
      12.     m_listCtrl.InsertColumn(3, "Size", LVCFMT_LEFT, rect.Width()/4);      
      13.  }  



       CEditControlView 繼承于FormView 關(guān)聯(lián)對話框IDD_EDITVIEW,為了后面可以new 將構(gòu)造函數(shù)改為publlic屬性(默認為protected)

      1. class CEditControlView : public CFormView  
      2.  {  
      3.  public:  
      4.     CEditControlView();           // protected constructor used by dynamic creation  

      為CEditControlView上的編輯控件添加控件型變量m_editCtrl


      為對話框添加OnSize消息,使編輯框與對話框等大

      1. void CEditControlView::OnSize(UINT nType, int cx, int cy)   
      2.  {  
      3.     CFormView::OnSize(nType, cx, cy);  
      4.       
      5.     // TODO: Add your message handler code here  
      6.     CFormView::ShowScrollBar(SB_VERT,FALSE);  
      7.     CFormView::ShowScrollBar(SB_HORZ,FALSE);  
      8.     //編輯框與窗口大小一樣  
      9.     if (GetSafeHwnd())  
      10.     {  
      11.         if (m_editCtrl.GetSafeHwnd())  
      12.         {  
      13.             CRect rect(0,0,cx,cy);  
      14.             m_editCtrl.MoveWindow(&rect);  
      15.         }  
      16.     }     
      17.  }  


      現(xiàn)在創(chuàng)建關(guān)聯(lián)樹控件的視圖類

      CLeftPaneView : public CFormView關(guān)聯(lián)對話框 IDD_TREEVIEW。

      為CLeftPaneView樹控件關(guān)聯(lián)一個控件類型的變量m_treeCtrl


      為對話框添加OnSize消息,使樹控件與對話框等大

      1. void CLeftPaneView::OnSize(UINT nType, int cx, int cy)   
      2.  {  
      3.     CFormView::OnSize(nType, cx, cy);  
      4.       
      5.     // TODO: Add your message handler code here  
      6.     if (GetSafeHwnd())  
      7.     {  
      8.         CRect rect;  
      9.         GetClientRect(&rect);  
      10.         if (m_treeCtrl.GetSafeHwnd())  
      11.             m_treeCtrl.MoveWindow(&rect);  
      12.     }     
      13.  }  

      添加OnInitialUpdate()虛函數(shù),初始化樹控件

      1. void CLeftPaneView::OnInitialUpdate()   
      2.  {  
      3.     CFormView::OnInitialUpdate();  
      4.       
      5.     // TODO: Add your specialized code here and/or call the base class  
      6.     m_ImageList.Create(IDB_BITMAP, 16, 1, RGB(255, 0, 255));      
      7.     m_treeCtrl.SetImageList(&m_ImageList, LVSIL_NORMAL);  
      8.       
      9.     m_hSplitterView = m_treeCtrl.InsertItem("Splitter View", 0, 0);  
      10.     m_hListCtrlView = m_treeCtrl.InsertItem("ListCtrl View", 1, 1);  
      11.     m_hEditView     = m_treeCtrl.InsertItem("EditCtrl View", 2, 2);  
      12.  }  
      13.    


      4、創(chuàng)建一個切分窗口類

      其實質(zhì)是在切分窗口添加編輯視圖和列表視圖對象。

      源文件中添加

      1. #include "ListControlView.h"  
      2. #include "EditControlView.h"  
      為了后面可以new CSplitterView將構(gòu)造函數(shù)改為publlic屬性(默認為protected)
      [html] view plaincopy
      1. class CSplitterView : public CView  
      2.  {  
      3.  public:    // changed from protected  
      4.     CSplitterView();           // protected constructor used by dynamic creation  
      5. //  
      6. //  
      7. };  


      1. int CSplitterView::OnCreate(LPCREATESTRUCT lpCreateStruct)   
      2.  {  
      3.     if (CView::OnCreate(lpCreateStruct) == -1)  
      4.         return -1;  
      5.       
      6.     // TODO: Add your specialized creation code here  
      7.     m_wndSplitter.CreateStatic(this, 2, 1);  
      8.    
      9.     CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;  
      10.    
      11.     m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CListControlView), CSize(150,0), pContext);  
      12.     m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CEditControlView), CSize(0,0), pContext);  
      13.       
      14.     return 0;  
      15.  }  

      添加成員變量

      1. // Attributes  
      2.  public:  
      3.     CSplitterWnd m_wndSplitter;  
      4.    

      添加WM_CREATE、WM_SIZE消息響應(yīng)
      1. int CSplitterView::OnCreate(LPCREATESTRUCT lpCreateStruct)   
      2.  {  
      3.     if (CView::OnCreate(lpCreateStruct) == -1)  
      4.         return -1;  
      5.       
      6.     // TODO: Add your specialized creation code here  
      7.     m_wndSplitter.CreateStatic(this, 2, 1);  
      8.       
      9.     CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;  
      10.       
      11.     m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CListCtrlView), CSize(150,0), pContext);  
      12.     m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CEditCtrlView), CSize(0,0), pContext);  
      13.       
      14.     return 0;  
      15.  }  
      16.    
      17.  void CSplitterView::OnSize(UINT nType, int cx, int cy)   
      18.  {  
      19.     CView::OnSize(nType, cx, cy);  
      20.       
      21.     // TODO: Add your message handler code here  
      22.     m_wndSplitter.MoveWindow(-2,-2,cx+4,cy+4);  
      23.     m_wndSplitter.SetRowInfo(0, cy-(cy/4), 0);  
      24.     m_wndSplitter.SetRowInfo(1, cy/4, 20);  
      25.     m_wndSplitter.RecalcLayout();  
      26.       
      27.  }  
      28.    

      5、創(chuàng)建右側(cè)切分窗口的框架類

      因為所有視圖都要放在框架窗口中,所以,右面板需要一個框架窗口。

      新建框架窗口類CRightPaneFrame,繼承自CFrameWnd。

      為了在框架中調(diào)用不同視圖類,添加成員變量,并定義視圖ID

      1. #include "SplitterView.h"  
      2.  #include "ListControlView.h"  
      3.  #include "EditControlView.h"  
      4.    
      5.  #define  VIEW_SPLITTER 1  
      6.  #define  VIEW_LISTCTRL 2  
      7.  #define  VIEW_EDIT     3  

      1. public:  
      2. CSplitterView* m_pSplitterView;  
      3. CListControlView* m_pListCtrlView;  
      4. CEditControlView* m_pEditCtrlView;  
      5. UINT m_nCurrentViewID;  

      添加虛函數(shù)

      1. BOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)   
      2.  {  
      3.     // TODO: Add your specialized code here and/or call the base class  
      4.     // TODO: Add your specialized code here and/or call the base class  
      5.       
      6.     m_pSplitterView = new CSplitterView;  
      7.     m_pSplitterView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_SPLITTER, pContext);  
      8.     SetActiveView(m_pSplitterView);  
      9.     m_pSplitterView->ShowWindow(SW_SHOW);  
      10.     m_pSplitterView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);  
      11.     m_nCurrentViewID = VIEW_SPLITTER;  
      12.       
      13.     m_pListCtrlView = new CListControlView;  
      14.     ((CView*) m_pListCtrlView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_LISTCTRL, pContext);  
      15.     m_pListCtrlView->ShowWindow(SW_HIDE);  
      16.     m_pListCtrlView->SetDlgCtrlID(VIEW_LISTCTRL);  
      17.       
      18.     m_pEditCtrlView = new CEditControlView;  
      19.     ((CView*) m_pEditCtrlView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, VIEW_EDIT, pContext);  
      20.     m_pEditCtrlView->ShowWindow(SW_HIDE);  
      21.     m_pEditCtrlView->SetDlgCtrlID(VIEW_EDIT);  
      22.       
      23.       
      24.     RecalcLayout();  
      25.       
      26.     return TRUE;  
      27.  // return CFrameWnd::OnCreateClient(lpcs, pContext);  
      28.  }  


      添加切換視圖的函數(shù)

      public:
        void SwitchToView(UINT nView);

      1. void CRightPaneFrame::SwitchToView(UINT nView)  
      2.  {  
      3.     CView* pOldActiveView = GetActiveView();  
      4.     CView* pNewActiveView = NULL;  
      5.    
      6.     switch (nView)  
      7.     {  
      8.     case    VIEW_SPLITTER:  
      9.                 pNewActiveView = (CView*) m_pSplitterView;  
      10.                 break;  
      11.    
      12.     case    VIEW_LISTCTRL:  
      13.                 pNewActiveView = (CView*) m_pListCtrlView;  
      14.                 break;  
      15.     case    VIEW_EDIT:  
      16.                 pNewActiveView = (CView*) m_pEditCtrlView;  
      17.                 break;  
      18.     }  
      19.    
      20.     if (pNewActiveView)  
      21.     {  
      22.         // don't switch when views are the same  
      23.         if (pOldActiveView == pNewActiveView) return;//不變  
      24.           
      25.         SetActiveView(pNewActiveView);//改變活動的視圖  
      26.         pNewActiveView->ShowWindow(SW_SHOW);//顯示新的視圖  
      27.         pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);  
      28.         pOldActiveView->ShowWindow(SW_HIDE);//隱藏舊的視圖  
      29.         pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);  
      30.         m_nCurrentViewID = nView;  
      31.           
      32.         RecalcLayout();//調(diào)整框架窗口  
      33.     }  
      34.  }  
      35.    
      36.    

      注意:

      pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
       
      實際上AFX_IDW_PANE_FIRST是為了解決多個VIEW的情況下消息轉(zhuǎn)發(fā)的問題,這是MFC內(nèi)部使用的一個固定的值,所有當(dāng)前的活動視圖都會切換到AFX_IDW_PANE_FIRST這個ID,主窗口收到的一些消息(比如命令、通知等等消息)會轉(zhuǎn)發(fā)給活動視圖來處理,框架通過這個ID來定位活動視圖。
       當(dāng)在某個SDI應(yīng)用程序中使用多個視圖并支持視圖切換時,很容易忽略這點,造成某些消息得不到正確的響應(yīng),

      因此當(dāng)激活某個視圖時也要把這個視圖的ID改成AFX_IDW_PANE_FIRST。

      當(dāng)主框架調(diào)整窗口布局時,即調(diào)用RecalcLayout()這個函數(shù)時,會將ID為AFX_IDW_PANE_FIRST的窗口/視(必須可見)作為最后一個視圖進行拉伸以填充剩余的區(qū)域。

      6.左面版添加視圖類成員變量

      在左面版也即樹視中添加成員變量,包含右面板和樹項

      1. // Attributes  
      2.  public:  
      3.     CImageList m_ImageList;  
      4.     HTREEITEM  m_hSplitterView;  
      5.     HTREEITEM  m_hListCtrlView;  
      6.     HTREEITEM  m_hEditView;  
      7.    
      8.     CRightPaneFrame* m_pRightPaneFrame;  
      頭文件class CLeftPaneView : public CFormView前加前置聲明,以便使用VIEW_SPLITTER等宏定義

      1. class CRightPaneFrame;  

      在源文件加

      [html] view plaincopy
      1. #include "RightPaneFrame.h"  


      添加當(dāng)樹形控件選項改變時消息響應(yīng),右邊視圖變化



      1. void CLeftPaneView::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)   
      2.  {  
      3.     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;  
      4.     // TODO: Add your control notification handler code here  
      5.     UINT        nView         = 0;  
      6.     HTREEITEM hSelectedItem = m_treeCtrl.GetSelectedItem();  
      7.       
      8.     if (hSelectedItem == m_hSplitterView)  
      9.         nView = VIEW_SPLITTER;  
      10.     else  
      11.         if (hSelectedItem == m_hListCtrlView)  
      12.             nView = VIEW_LISTCTRL;  
      13.         else  
      14.             if (hSelectedItem == m_hEditView)  
      15.                 nView = VIEW_EDIT;  
      16.               
      17.     if (nView) m_pRightPaneFrame->SwitchToView(nView);  
      18.    
      19.     *pResult = 0;  
      20.  }  


      7、修改MainFrame,創(chuàng)建靜態(tài)切分窗口

      在源文件中添加

      1. #include "LeftPaneView.h"  
      2.  #include "RightPaneFrame.h"  
      3.    

      修改OnCreateClient函數(shù)

      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_wndSplitter.CreateStatic(this, 1, 2))  
      5.     {  
      6.         TRACE0("Failed to create splitter window\n");  
      7.         return FALSE;  
      8.     }  
      9.       
      10.     // Get the client rect first for calc left pane size  
      11.     CRect rect;  
      12.     GetClientRect(&rect);  
      13.    
      14.     // create the left tree view first.  
      15.     if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPaneView), CSize(rect.Width()/3, 0), pContext))  
      16.     {  
      17.         TRACE0("Failed to create left pane view\n");  
      18.         return FALSE;  
      19.     }  
      20.    
      21.     // The right pane is a frame which and contain several different views.  
      22.     // The is can be set to active or non-active  
      23.     if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPaneFrame), CSize(0, 0), pContext))  
      24.     {  
      25.         TRACE0("Failed to create right pane frame\n");  
      26.         return FALSE;  
      27.     }  
      28.    
      29.     CLeftPaneView* pLeftPaneView     = (CLeftPaneView*)   m_wndSplitter.GetPane(0,0);  
      30.     pLeftPaneView->m_pRightPaneFrame = (CRightPaneFrame*) m_wndSplitter.GetPane(0,1);  
      31.       
      32.     // Set the left pane as the active view  
      33.     SetActiveView((CView*) m_wndSplitter.GetPane(0, 0));  
      34.    
      35.     return TRUE;  
      36.  }  
      37.    

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多