amig
asked on
Multiple view types of a doc in SDI application
I want multiple kind of views to be associated with the doc of my SDI application. (Think of Doc being a graph data, so one view is spreadsheet like, and other views can be pie chart, 3D views etc.) I do not want splitter window kind of scenario. But instead think of the complete CFrameWnd's client area to be covered by an exel like view, and there exist more windows one for each kind of view as a child of frame of the application, and these views can be moved, resized or closed like normal window -- and i can use menu items to show/hide a view )
What is the clenest way to achieve this in MFC.
What is the clenest way to achieve this in MFC.
ASKER
the point here is not to switch different kind of views depending on the viewtype, but instead its about simultaneously having different viewtype associated with the doc, that can be turned on/off individually by the user.
ASKER
the point here is not to switch different kind of views depending on the viewtype, but instead its about simultaneously having different viewtype associated with the doc, that can be turned on/off individually by the user.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As i mentioned in my original question, i would like to have more like a second solution from migel, where each view will have its own frame, thru which it can be dragged to be placed anywhere on the screen.
Ok
You can use such function:
CFrameWnd* CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
if (pDoc != NULL)
ASSERT_VALID(pDoc);
// create a frame wired to the specified document
ASSERT(m_nIDResource != 0); // must have a resource ID to load from
CCreateContext context;
context.m_pCurrentFrame = pOther;
context.m_pCurrentDoc = pDoc;
context.m_pNewViewClass = RUNTIME_CLASS(MyViewClass) ;
context.m_pNewDocTemplate = NULL;
if (m_pFrameClass == NULL)
{
TRACE0("Error: you must override CDocTemplate::CreateNewFra me.\n");
ASSERT(FALSE);
return NULL;
}
CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass- >CreateObj ect();
if (pFrame == NULL)
{
TRACE1("Warning: Dynamic create of frame %hs failed.\n",
m_pFrameClass->m_lpszClass Name);
return NULL;
}
ASSERT_KINDOF(CFrameWnd, pFrame);
if (context.m_pNewViewClass == NULL)
TRACE0("Warning: creating frame with no default view.\n");
// create new from resource
if (!pFrame->LoadFrame(IDR_RE SOURCE,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles
NULL, &context))
{
TRACE0("Warning: CDocTemplate couldn't create a frame.\n");
// frame will be deleted in PostNcDestroy cleanup
return NULL;
}
// it worked !
return pFrame;
}
You can use such function:
CFrameWnd* CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
if (pDoc != NULL)
ASSERT_VALID(pDoc);
// create a frame wired to the specified document
ASSERT(m_nIDResource != 0); // must have a resource ID to load from
CCreateContext context;
context.m_pCurrentFrame = pOther;
context.m_pCurrentDoc = pDoc;
context.m_pNewViewClass = RUNTIME_CLASS(MyViewClass)
context.m_pNewDocTemplate = NULL;
if (m_pFrameClass == NULL)
{
TRACE0("Error: you must override CDocTemplate::CreateNewFra
ASSERT(FALSE);
return NULL;
}
CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass-
if (pFrame == NULL)
{
TRACE1("Warning: Dynamic create of frame %hs failed.\n",
m_pFrameClass->m_lpszClass
return NULL;
}
ASSERT_KINDOF(CFrameWnd, pFrame);
if (context.m_pNewViewClass == NULL)
TRACE0("Warning: creating frame with no default view.\n");
// create new from resource
if (!pFrame->LoadFrame(IDR_RE
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles
NULL, &context))
{
TRACE0("Warning: CDocTemplate couldn't create a frame.\n");
// frame will be deleted in PostNcDestroy cleanup
return NULL;
}
// it worked !
return pFrame;
}
Hello,
This is how I handled this : use the standard CScrollView class. Add a member variable : CWnd m_pView. If you want to create an new view : m_pView = new CMyNewView, where CMyNewView is derived from another view class. If you want to draw the new view, override the view class of you main view object (here: CView)
CAppView::OnDraw(...)
{
// get client rect
// set client rect of the m_pView class
m_pView->OnDraw(...)
}
This is just a rought and simplified version ...
Tim Musschoot
This is how I handled this : use the standard CScrollView class. Add a member variable : CWnd m_pView. If you want to create an new view : m_pView = new CMyNewView, where CMyNewView is derived from another view class. If you want to draw the new view, override the view class of you main view object (here: CView)
CAppView::OnDraw(...)
{
// get client rect
// set client rect of the m_pView class
m_pView->OnDraw(...)
}
This is just a rought and simplified version ...
Tim Musschoot
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by : migel
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Roshan Davis
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by : migel
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Roshan Davis
EE Cleanup Volunteer
very very very good doc
For example:
Add memeber variable
int ViewType; // 0-graf, 1-Pie, ...
AddMemeberFunctions:
void OnPaintGraf(CPaint& dc);
void OnPaintPie(CPaint& dc);
...
In OnPaint function add:
void CMyView::OnPaint()
{
CPaintDC dc(this);
if( ViewType == 0 ) // Graf
OnPaintGraf(dc);
else if( ViewType == 1 ) // Pie
OnPaintPie(dc);
else
...
}