• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            MFC中如何將 CFormView放置到一個CDockablePane中

              最近再搭建一個平臺,設計到界面設計,然后就遇到題目中所述的問題,簡單的講就是要把CFormView放置到CDockablePane中,利用CDockablePane做成那種浮動的效果,郁悶的發現網絡上貌似關于這點的信息較少,有的也是說的含糊不清。沒辦法只能自己研究了 ~ 好吧,其他就都不說了,直接上代碼:
             CMainFrame類
            1 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
             2 {
             3     if(CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
             4         return -1;
             5     // enable Visual Studio 2008 style docking window behavior
             6     CDockingManager::SetDockingMode(DT_SMART);
             7     // enable Visual Studio 2008 style docking window auto-hide behavior
             8     EnableAutoHidePanes(CBRS_ALIGN_ANY);
             9     // create docking windows
            10     if(!CreateDockingWindows())
            11     {
            12         TRACE0("Failed to create docking windows\\n");
            13         return -1;    
            14     }
            15 
            16     m_wndManageDock.EnableDocking(CBRS_ALIGN_ANY);
            17     DockPane(&m_wndManageDock);
            18     return 0;
            19
             
            1 BOOL CMainFrame::CreateDockingWindows()
             2 {
             3   
             4    ////此處省略VS自動生成的一些代碼
             5 
             6     if (!m_wndManageDock.Create(_T("Manage Panel"), this, CRect(00200200), TRUE, 222
             7         WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT| CBRS_FLOAT_MULTI))
             8     {
             9         TRACE0("未能創建“屬性”窗口\n");
            10         return FALSE; // 未能創建
            11     }
            12 
            13     SetDockingWindowIcons(theApp.m_bHiColorIcons);
            14     return TRUE;
            15 
            16 }
             ManageDock.h
            1 #pragma once
             2 #include "ManagePanel.h"
             3 
             4 // CManageDock
             5 class CManageDock : public CDockablePane
             6 {
             7     DECLARE_DYNAMIC(CManageDock)
             8 
             9 public:
            10     CManageDock();
            11     virtual ~CManageDock();
            12 
            13 public:
            14     CManagePanel *m_wndManagePanel;
            15 
            16 protected:
            17     DECLARE_MESSAGE_MAP()
            18 public:
            19     afx_msg void OnPaint();
            20     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
            21 };
             ManageDock.cpp
             1 #include "stdafx.h"
             2 #include "EB Studio.h"
             3 #include "ManageDock.h"
             4 // CManageDock
             5 
             6 IMPLEMENT_DYNAMIC(CManageDock, CDockablePane)
             7 
             8 CManageDock::CManageDock()
             9 {
            10 
            11 }
            12 
            13 CManageDock::~CManageDock()
            14 {
            15 }
            16 
            17 
            18 BEGIN_MESSAGE_MAP(CManageDock, CDockablePane)
            19     ON_WM_PAINT()
            20     ON_WM_CREATE()
            21 END_MESSAGE_MAP()
            22 
            23 
            24 // CManageDock 消息處理程序
            25 
            26 void CManageDock::OnPaint()
            27 {
            28     CPaintDC dc(this); // device context for painting
            29     // TODO: 在此處添加消息處理程序代碼
            30     // 不為繪圖消息調用 CDockablePane::OnPaint()
            31     CRect rc;
            32     GetClientRect(rc);
            33     CBrush brush;  
            34     brush.CreateSolidBrush(RGB(255,255,255));   //背景設置為白色
            35 
            36     dc.FillRect(&rc,&brush);  
            37 }
            38 
            39 int CManageDock::OnCreate(LPCREATESTRUCT lpCreateStruct)
            40 {
            41     if (CDockablePane::OnCreate(lpCreateStruct) == -1)
            42         return -1;
            4
            44     // TODO:  在此添加您專用的創建代碼
            45 
            46     CRect rectDummy;
            47     rectDummy.SetRectEmpty();
            48 
            49     //     if(!m_wndFormView->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, rectDummy, this, 0, NULL));//重要的地方
            50     //     {
            51     //         TRACE0("未能創建文件視圖\n");
            52     //         return -1;      // 未能創建
            53     //     }
            54     m_wndManagePanel = CManagePanel::CreateOne(this);
            55 
            56     return 0;
            57 }
             ManagePanel.h
            1 #pragma once 2 #include "Resource.h" 3 4 // CManagePanel 窗體視圖 5 class CManagePanel : public CFormView 6 { 7 DECLARE_DYNCREATE(CManagePanel) 8 9 //protected:原來 10 public: 11 CManagePanel(); // 動態創建所使用的受保護的構造函數 12 virtual ~CManagePanel(); 13 14 static CManagePanel *CreateOne( CWnd *pParent );//自己加 15 16 17 public: 18 enum { IDD = IDD_MANAGEPANEL }; 19 #ifdef _DEBUG 20 virtual void AssertValid() const; 21 #ifndef _WIN32_WCE 22 virtual void Dump(CDumpContext& dc) const; 23 #endif 24 #endif 25 26 protected: 27 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 28 29 DECLARE_MESSAGE_MAP() 30 public: 31 virtual void OnInitialUpdate(); 32 afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); 33 };
             ManagePanel.cpp
            1 #include "stdafx.h" 2 #include "EB Studio.h" 3 #include "ManagePanel.h" 4 5 // CManagePanel 6 7 IMPLEMENT_DYNCREATE(CManagePanel, CFormView) 8 9 CManagePanel::CManagePanel() 10 : CFormView(CManagePanel::IDD) 11 { 12 13 } 14 15 CManagePanel::~CManagePanel() 16 { 17 } 18 19 void CManagePanel::DoDataExchange(CDataExchange* pDX) 20 { 21 CFormView::DoDataExchange(pDX); 22 } 23 24 BEGIN_MESSAGE_MAP(CManagePanel, CFormView) 25 ON_WM_MOUSEACTIVATE() 26 END_MESSAGE_MAP() 27 28 29 // CManagePanel 診斷 30 31 #ifdef _DEBUG 32 void CManagePanel::AssertValid() const 33 { 34 CFormView::AssertValid(); 35 } 36 37 #ifndef _WIN32_WCE 38 void CManagePanel::Dump(CDumpContext& dc) const 39 { 40 CFormView::Dump(dc); 41 } 42 #endif 43 #endif //_DEBUG 44 45 46 // CManagePanel 消息處理程序 47 48 void CManagePanel::OnInitialUpdate() 49 { 50 CFormView::OnInitialUpdate(); 51 52 GetParentFrame()->RecalcLayout(); 53 SetScrollSizes( MM_TEXT, CSize( 300, 300 ) ); 54 ResizeParentToFit(FALSE); 55 56 // TODO: 在此添加專用代碼和/或調用基類 57 } 58 59 CManagePanel *CManagePanel::CreateOne( CWnd *pParent ) 60 { 61 CManagePanel *p_ManagePanel = new CManagePanel; 62 63 //CMyFormView *pFormView = NULL; 64 //CRuntimeClass *pRuntimeClass = RUNTIME_CLASS(CMyFormView); 65 //pFormView = (CMyFormView *)pRuntimeClass->CreateObject(); 66 67 //CDockableFormViewAppDoc *pDoc = CDockableFormViewAppDoc::CreateOne();///////////////////////////////////////// 68 //pFormView->m_pDocument = pDoc;//////////////////////////////////////////////////////////////////////////////// 69 CCreateContext *pContext = NULL; 70 #if 0 71 if( !p_ManagePanel->CreateEx(0, NULL, NULL, WS_CHILD | WS_VISIBLE, CRect(0,0,205,157), 72 pParent, -1, pContext ) ) 73 #else 74 if (!p_ManagePanel->Create(NULL, NULL, WS_CHILD | WS_VISIBLE, CRect(0, 0, 300, 300), pParent, 0, pContext)) 75 #endif 76 //if( !pFormView->CreateEx( 0, AfxRegisterWndClass(0, 0, 0, 0), NULL, 77 // WS_CHILD | WS_VISIBLE, CRect( 0, 0, 205, 157), pParent, -1, pContext) ) 78 { 79 AfxMessageBox( _T("Failed in creating CMyFormView") ); 80 81 } 82 p_ManagePanel->OnInitialUpdate(); 83 return p_ManagePanel; 84 85 } 86 87 int CManagePanel::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 88 { 89 // TODO: 在此添加消息處理程序代碼和/或調用默認值 90 91 int nResult = 0; 92 93 CFrameWnd* pParentFrame = GetParentFrame(); 94 if(pParentFrame == pDesktopWnd) 95 { 96 // When this is docked 97 nResult = CFormView::OnMouseActivate(pDesktopWnd, nHitTest, message); 98 } 99 else 100 { 101 // When this is not docked 102 BOOL isMiniFrameWnd = pDesktopWnd->IsKindOf( RUNTIME_CLASS( CMiniFrameWnd ) ); 103 BOOL isPaneFrameWnd = pDesktopWnd->IsKindOf( RUNTIME_CLASS( CPaneFrameWnd ) ); 104 BOOL isMultiPaneFrameWnd = pDesktopWnd->IsKindOf( RUNTIME_CLASS( CMultiPaneFrameWnd ) ); 105 // pDesktopWnd is the frame window for CDockablePane 106 nResult = CWnd::OnMouseActivate( pDesktopWnd, nHitTest, message ); 107 108 //nResult = CWnd::OnMouseActivate( pDesktopWnd, nHitTest, message ); 109 //if( nResult == MA_NOACTIVATE || nResult == MA_NOACTIVATEANDEAT ) 110 // return nResult; 111 //if (pDesktopWnd != NULL) 112 //{ 113 // // either re-activate the current view, or set this view to be active 114 // //CView* pView = pDesktopWnd->GetActiveView(); 115 // //HWND hWndFocus = ::GetFocus(); 116 // //if (pView == this && 117 // // m_hWnd != hWndFocus && !::IsChild(m_hWnd, hWndFocus)) 118 // //{ 119 // // // re-activate this view 120 // // OnActivateView(TRUE, this, this); 121 // //} 122 // //else 123 // //{ 124 // // // activate this view 125 // // pDesktopWnd->SetActiveView(this); 126 // //} 127 //} 128 } 129 return nResult;

            posted on 2010-11-07 15:11 蝸牛也Coding 閱讀(8300) 評論(3)  編輯 收藏 引用

            評論

            # re: MFC中如何將 CFormView放置到一個CDockablePane中[未登錄] 2010-11-07 18:27 zhaoyg

            后半部分的代碼沒法看。

            浮動時,如果在CFormView上單擊就會崩掉,原因是浮動時指向的父類發生了變化,所以我想請問,這塊你是怎么處理的  回復  更多評論   

            # re: MFC中如何將 CFormView放置到一個CDockablePane中 2010-11-07 18:59 蝸牛也Coding

            @zhaoyg
            都在 OnMouseActivate 函數里了  回復  更多評論   

            # re: MFC中如何將 CFormView放置到一個CDockablePane中 2014-02-13 18:29 ren

            注釋掉的創建部分,指針調用
            為何不用友元類聲明下,就可以用了的。CreateOne,有點繞。
            感謝博主分享。  回復  更多評論   

            <2015年9月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            導航

            統計

            常用鏈接

            留言簿(8)

            隨筆檔案(78)

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久成人精品无码| 久久久久久免费视频| 伊人久久大香线焦AV综合影院| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品久久人人爽天天玩人人妻 | 久久精品成人欧美大片| 久久久综合九色合综国产| 久久国产亚洲精品无码| 久久久久久久亚洲Av无码| 亚洲午夜久久久久久久久久| 2021国内久久精品| 久久亚洲sm情趣捆绑调教| 久久91精品国产91久| 97视频久久久| 亚洲女久久久噜噜噜熟女| 亚洲av日韩精品久久久久久a| 日韩人妻无码精品久久久不卡| 伊人色综合久久天天人手人婷| 精品久久久中文字幕人妻| 亚洲午夜久久久影院伊人| 久久精品国产亚洲av麻豆小说| 国产精品一区二区久久不卡| 久久er国产精品免费观看2| 777久久精品一区二区三区无码 | 精品久久国产一区二区三区香蕉| 欧美久久综合性欧美| 久久性生大片免费观看性| 狠狠色综合网站久久久久久久高清| 狼狼综合久久久久综合网| 欧美精品一区二区精品久久| 久久久国产精华液| 无码伊人66久久大杳蕉网站谷歌| 久久午夜羞羞影院免费观看| AA级片免费看视频久久| 久久大香萑太香蕉av| 久久天天躁狠狠躁夜夜96流白浆| 欧美激情精品久久久久| 无码任你躁久久久久久老妇| 久久精品亚洲中文字幕无码麻豆| 日本久久久久久中文字幕| 久久久国产99久久国产一|