Solved

Multiple view types of a doc in SDI application

Posted on 2001-07-10
9
295 Views
Last Modified: 2013-12-20
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.
0
Comment
Question by:amig
9 Comments
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6268763
You may add different type of views (member variable) and in the same way different type of OnPaint functions.

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
      ...
}
0
 

Author Comment

by:amig
ID: 6268871
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.
0
 

Author Comment

by:amig
ID: 6268919
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.
0
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
ID: 6270376
Hi!
1. (simplest way)
use CSplitterWnd - you can use "static" splitter with different views.
2. Create Views manually.
Views can tile on one child frame ir each view can have it`s own child frame.
What you want?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:amig
ID: 6281891
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.
0
 
LVL 12

Expert Comment

by:migel
ID: 6282239
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::CreateNewFrame.\n");
          ASSERT(FALSE);
          return NULL;
     }
     CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject();
     if (pFrame == NULL)
     {
          TRACE1("Warning: Dynamic create of frame %hs failed.\n",
               m_pFrameClass->m_lpszClassName);
          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_RESOURCE,
               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;
}

0
 
LVL 1

Expert Comment

by:Tim_Musschoot
ID: 6364024
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
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490287
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
0
 

Expert Comment

by:q3tech
ID: 39731427
very very very good doc
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 91
Separate files macro - Errors on larger data set 18 65
mapAB Challlenge 35 124
Making an alias 7 79
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now