View windows are specific in MFC. They are mainly designed as part of MFC’s document view architecture. Of course, you can use it without document connection like you did in dialog (CNxfRitsumenInDlg
and CNxkCView
) at your own risk, but results of such experiments sometimes can be really fun. That is what’s really happen in your project. The behavior problem after double clicking view and closing the floating bar is not a problem of Prof-UIS. This problem is brought by the following two methods in MFC source code:
void CView::OnActivateView(BOOL bActivate, CView* pActivateView, CView*)
{
UNUSED(pActivateView); // unused in release builds
if (bActivate)
{
ASSERT(pActivateView == this);
// take the focus if this frame/view/pane is now active
if (IsTopParentActive())
SetFocus();
}
}
void CView::OnActivateFrame(UINT /*nState*/, CFrameWnd* /*pFrameWnd*/)
{
}
int CView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
int nResult = CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
if (nResult == MA_NOACTIVATE || nResult == MA_NOACTIVATEANDEAT)
return nResult; // frame does not want to activate
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 be active
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;
}
Both methods do what is absolutely not needed for view window detached from document and created inside dialog. The
CView::OnActivateView()
invokes the
SetFocus()
even without view visibility check and even worst - without checking whether the view window is part of document view architecture. The
CView::OnMouseActivate()
has the same bad problems – it invokes the
pParentFrame->SetActiveView(this)
code without analyzing kind of view window and its connection with document object.
We fixed the problem in scope of your test project. We added the
CNxkCView::OnActivateView()
method which does not invoke parent class method. We handled the
WM_MOUSEACTIVATE
message in the
CNxkCView::WindowProc()
virtual method. Here is the modified version of your project:
http://www.prof-uis.com/download/forums/tmp/SampleMDITest_modified_for_tera_t.zip