CFrameWnd* pParentFrame = GetParentFrame();
if (pParentFrame != NULL)
{
// eat it if this will cause activation
ASSERT(pParentFrame == pDesktopWnd ||pDesktopWnd->IsChild(pParentFrame));
// either re-activate the current view, or set this view to beactive
CView* pView = pParentFrame->GetActiveView();
HWND hWndFocus = ::GetFocus();
if (pView == this &&
m_hWnd != hWndFocus && !::IsChild(m_hWnd, hWndFocus))
{
// re-activate this view
OnActivateView(TRUE, this, this);
}
else
{
// activate this view
pParentFrame->SetActiveView(this);
}
}
return nResult;
}
另外,在CView::PostNcDestroy(),实现了CView类的自我销毁,这是因为CView类是可以动态生成的(DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE)。
// self destruction
void CView::PostNcDestroy()
{
// default for views is to allocate them on the heap
//the default post-cleanup is to ‘delete this‘.
//never explicitly call ‘delete‘ on a view
delete this;
基本上,修改了CView继承类的这几个地方,直接返回不要调用基类相应的成员函数,就可以在对话框上使用。
下面举例,用向导生成对话框应用程序,对话框类为CMyDigalog。
从CHTMLView类继承一个CHTMLCtrl类,建立相应的消息处理函数并修改以下几个地方:
// CHTMLCtrl 消息处理程序
int CHTMLCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINTmessage)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
//return CHtmlView::OnMouseActivate(pDesktopWnd,nHitTest, message);
}
void CHTMLCtrl::OnDestroy()
{
//CHtmlView::OnDestroy();
// TODO: 在此处添加消息处理程序代码

CWnd::OnDestroy();
}
void CHTMLCtrl::PostNcDestroy()
{
// TODO: 在此添加专用代码和/或调用基类
//CHtmlView::PostNcDestroy();
}
void CHTMLCtrl::OnActivateFrame(UINT nState, CFrameWnd*pDeactivateFrame)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-32922-3.html
中国军队尤其海军必须始终头顶国耻心记仇恨
此时此刻特别怀念毛主席
谋求战略均衡点