Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hot-swapping MDI Child window views

10 views
Skip to first unread message

Newsgroupie

unread,
Aug 19, 2009, 5:10:47 AM8/19/09
to
Hello fellow Newsgroupies!

I am writing an MDI application which requires an MDI child window to
display different views at different times (depending upon certain
state data in the underlying document).

I can't simply create a new MDI child with a different view in it
looking at the same document as this would quickly fill up the MDI
frame window and become very confusing.

So I it needs to be able to seamlessly change views at any time,
returning to a previously created view if possible and to be able to
adjust itself to a new size if the MDI child window has been resized
in the meantime.

I have considered using property sheets / pages embedded into the MDI
child but would rather do it this way if possible.

The reason for this is that in one state I would need to show a CForm
based view, in another a CScroll based view and in yet another a CList
(report) based view.

Any help, samples or examples gratefully received!

Many thanks in advance,

'Newsgroupie',
England

Joseph M. Newcomer

unread,
Aug 19, 2009, 10:47:44 AM8/19/09
to
There is an example for CDocument::AddView that shows how to swap views for an SDI view.
If I were going to attempt this, I would study that code and see how I could adapt it.

But what I would have chosen in most cases is the tabbed control view (see the CTabView
class in www.codeproject.com but note also there is a CTabView in VS2008 SP1)
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

AliR

unread,
Aug 19, 2009, 10:55:23 AM8/19/09
to
The only solution that comes to mind is to open a new childframe with the
desired view in it and close the current childframe.

So basically you have as many CMultiDocTemplate objects as you have
different views. And you will need to keep a pointer to each one that you
have added to the list of document templates.

CMyWinApp::InitInstance()
{
....
m_pMyView1Template = new CMulitDocTemplate(....);
AddDocTemplate(m_pMyView1Template);
m_pMyView2Template = new CMulitDocTemplate(....);
AddDocTemplate(m_pMyView2Template);
m_pMyView3Template = new CMulitDocTemplate(....);
AddDocTemplate(m_pMyView3Template);
.....
}


Here is an example of how to create a new document with an existing Doc. The
Rect is the windowrect of the current frame you will be replacing.
void CMainFrame::CreateView1(CDocument *pDoc,const CRect &Rect)
{
CFrameWnd* FrameWnd = m_pMyView1Template->CreateNewFrame(pDoc ,NULL);
if (FrameWnd)
{
FrameWnd->InitialUpdateFrame(NULL,TRUE);
FrameWnd->SetFocus();
FrameWnd->SetWindowPos(NULL,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER);
}
}

Simply close the old view by sending it a WM_CLOSE message.

AliR.


"Newsgroupie" <buz...@yahoo.co.uk> wrote in message
news:68866b77-9af1-4d7d...@g31g2000yqc.googlegroups.com...

0 new messages