问题描述
我在 CChildFrame
中添加了一个导航侧边栏,方法是在其中创建一个 CSplitterWnd
并添加一个 CScrollView
和一个 CListView
作为基于
这些代码示例并不是最合适的,因为它们创建的是 CWnd
派生的窗格,而不是 CView
-派生的.视图与文档没有某种关联.您需要调用 CDocument::AddView()
方法,将您创建的每个视图添加到文档的视图列表中.pContext
参数包含指向文档以及其他成员的指针.
将下面的代码放在您的文档类中,以验证您的视图是否已正确创建并关联到文档:
POSITION pos = GetFirstViewPosition();而(位置){CView *pVw = GetNextView(pos);AfxMessageBox(typeid(*pVw).name(), MB_OK | MB_ICONINFORMATION);}
也在每个视图类中:
CDocument *pDoc = GetDocument();if (pDoc) AfxMessageBox(pDoc->GetTitle(), MB_OK | MB_ICONINFORMATION);else AfxMessageBox(视图没有关联的文档!");
注意:CChildFrame
类的默认实现调用 CSplitterWnd::Create()
而不是 CSplitterWnd::CreateStatic()
来创建拆分器窗口,如果将拆分器窗口移动到最后,它会破坏脱离视图的窗格.然后,如果您将其移回,它会使用文档模板或现有视图中的信息再次创建它们.如果您最终创建了一个动态拆分器窗口,您可能也需要覆盖此行为.最好检查您使用的版本的 MFC 源.
I added a navigation sidebar in my CChildFrame
by creating a CSplitterWnd
in it and by adding a CScrollView
and a CListView
as splitter panes based on this answer. Is there a textbook way to do this? I'm asking because I ran into multiple side-effects like the document name no longer showing up in the applications titlebar or mousewheel no longer working for the CScrollView
.
I guess, I need to redirect messages arriving in my CChildFrame
somehow to make my CScrollView
the default receiver for CView
-related messages as the CSplitterWnd
breaks the flow, because it's not derived from CView. Can someone point me in the right direction?
(Note: This is still done with VS 2008.)
Update: I just created a separate question for the application window title update issue: MFC: After applying a CSplitterWnd to my CChildFrame the main window title isn't updated any more
These code samples are not the most suitable ones, because they create CWnd
-derived panes, not CView
-derived ones. The views are not in some way associated to the document. You need to call the CDocument::AddView()
method, to add every view you created to the document's list of views. The pContext
parameter contains a pointer to the document, among other members.
Put the code below in your document class, to verify that your views have been created and associated to the document correctly:
POSITION pos = GetFirstViewPosition();
while (pos)
{
CView *pVw = GetNextView(pos);
AfxMessageBox(typeid(*pVw).name(), MB_OK | MB_ICONINFORMATION);
}
Also in each view class:
CDocument *pDoc = GetDocument();
if (pDoc) AfxMessageBox(pDoc->GetTitle(), MB_OK | MB_ICONINFORMATION);
else AfxMessageBox("The view has no associated Document!");
Note: The default implementation of the CChildFrame
class calls CSplitterWnd::Create()
rather than CSplitterWnd::CreateStatic()
to create the splitter window, and if you move the splitter window to the end it destroys the panes that come off-view. Then if you move it back it creates them again, using the information in the document template or the existing views. You may need to override this behavior too, if you finally make a dynamic splitter window. Better check the MFC source of the version you are using.
这篇关于MFC:如何在将 CView 替换为在窗格中具有两个 CView 派生类的 CSplitterWnd 后修复 MDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!