• <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)

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲国产小视频精品久久久三级 | 亚洲国产精品嫩草影院久久| 亚洲精品高清国产一久久| 中文字幕亚洲综合久久2| 久久这里都是精品| 久久久久人妻精品一区| 日本精品一区二区久久久| 久久婷婷五月综合色奶水99啪| 久久国产精品-国产精品| 亚洲精品成人久久久| 日韩乱码人妻无码中文字幕久久| 日韩亚洲欧美久久久www综合网| 欧美国产成人久久精品| 久久精品国产亚洲av麻豆色欲| 久久精品国产亚洲AV不卡| 久久w5ww成w人免费| 思思久久99热只有频精品66| 久久精品国产69国产精品亚洲| 久久狠狠爱亚洲综合影院| 国产精品成人久久久久久久| 久久久精品2019免费观看| 亚洲精品乱码久久久久久自慰| 久久精品中文字幕第23页| 九九99精品久久久久久| 久久青青草原精品国产| 精品久久久无码21p发布 | 色综合久久久久| 国内精品久久久久久99| 狠狠综合久久综合88亚洲| 欧美色综合久久久久久 | 久久99精品久久久久子伦| 2021国产精品午夜久久| 亚洲日本va午夜中文字幕久久| 国产精品欧美亚洲韩国日本久久| 免费观看成人久久网免费观看| 久久精品一本到99热免费| 精品久久久久久无码专区不卡| 亚洲va中文字幕无码久久| 日本久久久久亚洲中字幕| 粉嫩小泬无遮挡久久久久久| 97久久超碰国产精品旧版|