MFC Multiple views for different graphs
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: MFC Multiple views for different graphs

  1. #1
    Join Date
    May 2012
    Posts
    8

    MFC Multiple views for different graphs

    Hello,

    I am seeking to create an MFC application which displays several different graphs in different windows. For this I was thinking of using an MDI CFormView app in which each window/view represents a different graph.

    Currently I am using a dialog based solution which displays only one graph, however my future needs will require more graphs to be displayed simultaneously so I'm accounting for that now.

    If I were to use MDI would I be able to create multiple views, each with its own title? Blocking the File->New button is simple enough and I can deal with the document/view architecture. Basically I would like to know if MDI is the best approach for this or not.

    -ocm

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,013

    Re: MFC Multiple views for different graphs

    Quote Originally Posted by ocm7 View Post
    If I were to use MDI would I be able to create multiple views, each with its own title? Blocking the File->New button is simple enough and I can deal with the document/view architecture. Basically I would like to know if MDI is the best approach for this or not.
    Yes, you'll be able to create multiple views, also "each with its own title".
    If you ask about "the best approach" withing MFC then IMHO, yes, it is the best.
    Victor Nijegorodov

  3. #3
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: MFC Multiple views for different graphs

    You have two choices: register different templates for each graph and invoke new file for each of them.
    The drawback is you will have document object created for each template.

    If you are using the same data to display different graph, you can use template to create initial frame/view/doc and create frames for all other views using the same document instance.
    I did it for my database managing my project, to display different views for database.

    If you need sample, let me know.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    May 2012
    Posts
    8

    Re: MFC Multiple views for different graphs

    Quote Originally Posted by VictorN View Post
    Yes, you'll be able to create multiple views, also "each with its own title".
    If you ask about "the best approach" withing MFC then IMHO, yes, it is the best.
    Thank you, I decided to go for MDI, Multi View Single Doc

    Quote Originally Posted by JohnCz View Post
    You have two choices: register different templates for each graph and invoke new file for each of them.
    The drawback is you will have document object created for each template.

    If you are using the same data to display different graph, you can use template to create initial frame/view/doc and create frames for all other views using the same document instance.
    I did it for my database managing my project, to display different views for database.

    If you need sample, let me know.
    I have a sample of instantiating multiple views of the same document using CMultiDocTemplate, but I have a few questions.

    My Applications takes data from a proprietary USB HID device, I have communications USB-PC set up and working properly. The data sent via USB contains information for several different graphs, unfortunately I cannot go more into detail regarding the type of data being sent. Can, and should, I handle the data reception and parsing in the document class? And, do I send the parsed data to each separate view from the Document class, or do I poll the Document class from each view? The parsed data is to be stored in a vector (or similar) data type and then plotted. I will have a different vector for each graph.

    Thanks, ocm

  5. #5
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: MFC Multiple views for different graphs

    That depends.
    I do not know how received data is delivered.
    If delivery contains data that is common for all graphs, I would keep data in the document and each view would ask document for needed data to draw view specific graph(s).

    If data is sent in chunks separately for each graph, you have two scenarios:
    1. You want to safe data in a file for later retrieval. I would still keep data in a document and use document to orchestrate serialization. Store data in a document in some kind of custom data type (structure, class) for views to consume.
    2. You do not want to safe data. This poses a very important question: do you need a document object at all? It is for you to decide.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    May 2012
    Posts
    8

    Re: MFC Multiple views for different graphs

    Quote Originally Posted by JohnCz View Post
    That depends.
    I do not know how received data is delivered.
    If delivery contains data that is common for all graphs, I would keep data in the document and each view would ask document for needed data to draw view specific graph(s).

    If data is sent in chunks separately for each graph, you have two scenarios:
    1. You want to safe data in a file for later retrieval. I would still keep data in a document and use document to orchestrate serialization. Store data in a document in some kind of custom data type (structure, class) for views to consume.
    2. You do not want to safe data. This poses a very important question: do you need a document object at all? It is for you to decide.
    A good way to picture it would be the data being received is akin to a structure, my program then extracts the content of that structure and each member is plotted in a different graph. Serialization is desirable, so I'll go with Single Doc/Multi View.

    Also, When the MDI Application is instantiated it defines a certain size for the window, how can I make this size the minimum size? As in, the user would be unable to make the window any smaller. I can handle reorganization of controls upon resizing. I can set a fixed minimum size, thats easy. I'm just having some trouble doing this dynamic minimum size

  7. #7
    Join Date
    May 2012
    Posts
    8

    Re: MFC Multiple views for different graphs

    Quote Originally Posted by ocm7 View Post
    Also, When the MDI Application is instantiated it defines a certain size for the window, how can I make this size the minimum size? As in, the user would be unable to make the window any smaller. I can handle reorganization of controls upon resizing. I can set a fixed minimum size, thats easy. I'm just having some trouble doing this dynamic minimum size
    Ok, I solved it but I wouldn't be surprised if there is a more efficient method. I added ON_WM_GETMINMAXINFO to the Message Map and overrode the OnGetMinMaxInfo as follows:

    Code:
    void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
    {
    	static BOOL SizeSet = FALSE;
    	static int xMin;
    	static int yMin;
    
    	CMDIFrameWnd *pView = (CMDIFrameWnd*) AfxGetMainWnd();
    	
    	if(pView && SizeSet == FALSE)
    	{
    		CRect rView;
    		pView->GetWindowRect(rView);
    		xMin = rView.Width();
    		yMin = rView.Height();
    
    		lpMMI->ptMinTrackSize.x=xMin;
    		lpMMI->ptMinTrackSize.y=yMin;
    		SizeSet = TRUE;
    	}
    
    	else if (SizeSet == FALSE)
    		CFrameWnd::OnGetMinMaxInfo(lpMMI);
    
    	else if(pView && SizeSet == TRUE)
    	{
    		lpMMI->ptMinTrackSize.x=xMin;
    		lpMMI->ptMinTrackSize.y=yMin;
    	}
    
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center