Adding a view to MDI, by hand, special requirements ???
I have been trying without success to add a view to a MDI program. The goal
is: for a document, two active views, each displayed in separate windows,
both constantly updated. The Microsoft chart indicates the view is a child of
a window, so the code is intended to:
1. Create a child frame of the application mainframe.
2. Creat a view and make it a child of the above child frame.
3. Add the view to the document.
It appears that while walking the views, MFC doesn't like the hWnd of the
view. The view was created by the wizard.
CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd* pParentFrame = new CMDIChildWnd;
CRect rect(200, 200, 600, 600);
WS_THICKFRAME | WS_CHILD | WS_VISIBLE | WS_VSCROLL, rect, pMainWnd, NULL );
HWND h_Parent = pParentFrame->m_hWnd;
FloatView* pFloatView = new FloatView;
HWND h_View = pFloatView->m_hWnd;
SetParent( h_View, h_Parent );
this->AddView( pFloatView );
pFloatView->SetScrollSizes( MM_TEXT, CSize(100, 100) );
Fails in doccore.cpp at ASSERT(::IsWindow(pView->m_hWnd));
// assumes 1 doc per frame
// walk all frames of views (mark and sweep approach)
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
CView* pView = GetNextView(pos);
if (pView->IsWindowVisible()) // Do not count invisible windows.
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame != NULL)
pFrame->m_nWindow = -1; // unknown