(MFC)Vs2010制作Visual Studio风格的停靠侧栏窗口(CDockablePane里嵌套FormView表单视图) (五)
ruct); virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
[cpp]
// CMfcFormView 消息处理程序 int CMfcFormView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFormView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 return 0; } BOOL CMfcFormView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { // TODO: 在此添加专用代码和/或调用基类 return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } // CMfcFormView 消息处理程序
int CMfcFormView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
return 0;
}
BOOL CMfcFormView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
在CSolution.h里声明CMfcFormView*类型的指针变量
[cpp]
protected: CMfcFormView* m_pformView; protected:
CMfcFormView* m_pformView;
在CSolution的构造函数里创建CMfcFormView对象
[cpp]
CSolutionWnd::CSolutionWnd() { m_pformView = (CMfcFormView*) (RUNTIME_CLASS(CMfcFormView)->CreateObject()); } CSolutionWnd::CSolutionWnd()
{
m_pformView = (CMfcFormView*) (RUNTIME_CLASS(CMfcFormView)->CreateObject());
}
在CSolution的OnCreate函数里创建FormView
[cpp]
int CSolutionWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDockablePane::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 RECT rect; GetClientRect(&rect); m_pformView->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, rect, this, 123, NULL); return 0; } int CSolutionWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
RECT rect;
GetClientRect(&rect);
m_pformView->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, rect, this, 123, NULL);
return 0;
}
在CSolution的OnSize函数里调整FormView填充整个DockablePane区域
[cpp]
void CSolutionWnd::OnSize(UINT nType, int cx, int cy) { CDockablePane::OnSize(nType, cx, cy); // TODO: 在此处添加消息处理程序代码 if (GetSafeHwnd() == NULL) { return; } if(m_pformView->GetSafeHwnd()!=NULL) { CRect rect; GetClientRect(rect); m_pformView->SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER); } } void CSolutionWnd::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
if (GetSafeHwnd() == NULL)
{
return;
}
if(m_pformView->GetSafeHwnd()!=NULL)
{
CRect rect;
GetClientRect(rect);