MFC中如何将 CFormView放置到一个CDockablePane中
来源:互联网 发布:羽毛球比赛直播软件 编辑:程序博客网 时间:2024/05/17 04:13
最近再搭建一个平台,设计到界面设计,然后就遇到题目中所述的问题,简单的讲就是要把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
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(0, 0, 200, 200), 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 }
2 {
3
4 ////此处省略VS自动生成的一些代码
5
6 if (!m_wndManageDock.Create(_T("Manage Panel"), this, CRect(0, 0, 200, 200), 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 };
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 }
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 窗体视图
5class CManagePanel :public CFormView
6 {
7 DECLARE_DYNCREATE(CManagePanel)
8
9//protected:原来
10public:
11CManagePanel();// 动态创建所使用的受保护的构造函数
12virtual ~CManagePanel();
13
14static CManagePanel *CreateOne( CWnd *pParent );//自己加
15
16
17public:
18enum { IDD = IDD_MANAGEPANEL };
19 #ifdef _DEBUG
20virtualvoid AssertValid() const;
21 #ifndef _WIN32_WCE
22virtualvoid Dump(CDumpContext& dc) const;
23#endif
24#endif
25
26protected:
27virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
28
29 DECLARE_MESSAGE_MAP()
30public:
31virtualvoid OnInitialUpdate();
32 afx_msgint 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
19void 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
32void CManagePanel::AssertValid()const
33 {
34 CFormView::AssertValid();
35 }
36
37 #ifndef _WIN32_WCE
38void 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;//////////////////////////////////////////////////////////////////////////////69CCreateContext *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
87int 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;
- MFC中如何将 CFormView放置到一个CDockablePane中
- 将CFormView嵌入到CDockablePane中
- 将CFormView嵌入到CDockablePane中
- 将CFormView嵌入到CDockablePane中
- 将CFormView嵌入到CDockablePane中
- 在CDockablePane中嵌入CFormView
- MFC中CFormView
- MFC中利用CDockablePane实现悬浮窗
- ThinkPHP3.2.3将session放置到指定文件夹中
- MFC中如何将焦点设置到指定控件上
- MFC中如何将焦点设置到指定控件上
- MFC中如何将焦点设置到指定控件上
- 如何将mfc中的数据导入到Excel中
- Linux中如何将程序放置后台运行
- 如何Latex中把下标放置到正下方
- MFC MDI在CFormView中当前关闭窗口的代码
- MFC中发一些CDockablePane 关闭等编程问题。强烈推荐!!!!
- 如何将一个位图拷贝到另一个位图中
- 指针秘密之字符串常量
- [K/3Cloud] 单据转换插件执行顺序
- AC算法详解
- 整型与字符型之间转化
- 改变对象的显示顺序--类似绘图次序的前置和后置
- MFC中如何将 CFormView放置到一个CDockablePane中
- 点击屏幕空白处让键盘消失的方法
- CSS背景色镂空技术实际应用及进阶
- java中int与byte〔4〕的相互转换
- json数据与字符串的相互转化
- 关于php中Warning: date(): It is not safe to rely on the system's timezone settings.解决
- checkedcomboboxedit控件的值的绑定 并选择指定项
- Struts2的工作原理
- Source Insight