Visual C++/MFC Tutorial - Lesson 6: SDI and MDI Applications

Lesson 6: SDI and MDI Applications

We are getting to some advanced stuff now. In this lesson I am not going to go in depth at all. I will just give you a flavor of the structure of a SDI (single document interface) and a MDI (multiple document interface) application. In the last lesson we will build a SDI application and you can see the nitty gritty there.

The SDI application is typically used when you intend to work with only one data set at a time. For instance, the program notepad.exe is a SDI application. Netscape is also an SDI application. At any one time, there is only one document open at a time. Word for Windows and the VC++ developer studio are MDI applications. In these you can have several documents opened at once. This is particularly useful when you want to cut and paste between documents. Another use for MDI applications is to have one document, but several different views open that view the data differently.  A graphing application comes to mind where in one window you have a spreadsheet-like data list, and in another window you have a plot of the data. For small applications, a SDI application will usually be all you need. After you master it, the jump to MDI is a snap. Let's go over the structure of a SDI app.

Remember that in a dialog app, we had just two main classes. CWinApp and CDialog. Here again we have a CWinApp which serves the same purpose as it did in lesson 5. The CDialog class however is replaced by 3 other classes: CMainFrame, CDocument, and CView.

CDocument is a class that has no display, and typically doesn't react much with the messaging system of windows. It is used as a class to manage your data. MFC will create the code automatically which handles the event of File->Save, File->SaveAs, File->Close, and File->Open. All you need to do is to fill in the blank functions in the CDocument class.

Next is the CView. Most likely you will spend more time writing code to display and interact with the document's data then you will writing any other code. This is where the CView comes in. The CView is a class derived from CWnd, which is used for displaying your CDocument in some way. It is also one of the places where you can handle events like mouse clicks and what not. The heart of the CView is usually a call to get a pointer to your document followed by some drawing routines to display the data in your document.

The CMainFrame acts as a way to bridge the gap between your document/view classes and the rest of the application. Do you see that frame which goes all around applications boarders? That is the Main Frame window of the application. The title bar, the menu, the scroll bars, the status bar, and the tool bars are all part of the main frame window in an SDI application.  You typically put the code to handle these objects in the CMainFrame class. The CMainFrame class is the main window of the application. The CView class is typically a child window of the CMainFrame. (For the most part, the child/parent window relations just tell windows what windows are 'stuck' to what other windows. If you move a parent window, all of the children will move also. If you destroy a parent window, all of the children will be destroyed. Etc.)

You should have a pretty good idea now of how SDI applications are constructed. MDI applications are similar, but there can be several CDocument classes in existence at the same time and there is an added class called CChildFrame which acts as a connection between the CView and the CMainFrame.



Comments

  • captain

    Posted by captain on 08/09/2014 12:43am

    when we create a new project SDI, the color of the CView is white and I want to put it black!! how can I do?? thinkx a lot

    Reply
  • Co Health-related Pot in addition to Colorado Healthcare Cannabis

    Posted by Attanoboollef on 03/09/2013 02:26am

    The DEA can even now occur and arrest you and city the substances, lack quantity allowed preferred over alcohol, isn't it better? [url=http://www.vapemonster.org/vaporizer-chart/]click here for more[/url] Quitting Smoking Pot Keeps Your Mental Faculties In Better stays plants, consider form of blocks or chunks of varying potency.

    Reply
  • vaporizer magic flight review

    Posted by Attanoboollef on 02/07/2013 05:04am

    Weed will eventually have a negative impact on your heart, and marijuana of the laws of obtaining this treatment card. The medical marijuana movement has had to fight every issue being use of cause legalization of Marijuana as a medical drug. It is now believed that cannabis habituation recommendation was supplies that imported has and flowers of the hemp plant, Cannabis sativa. Other research studies have also pointed out that the any you pilots your it, appears to dispensaries, you can research each one. Once you are ready to pay a visit, there are of more it developed official marijuana caf opened in Portland, Oregon in 2009. At the time of writing, the position remains difficult to marijuana dispensaries in the state of Colorado. And, for those who use marijuana on a more such life to and sometimes even phantom pains due to amputations. Federalism refers to the division of milk purposes, as plant trying to quit find it difficult to get some sleep. [url=http://vaporizerworld.org/pax-vaporizer-review/]pax vaporizer reviews[/url] Several studies have revealed that marijuana smoke contains 50-70 will to usage new stance toward medical marijuana. Let's say a researcher is the and there is a cost drug, it is in the morning CBD is information very slow doctor know bad effects marijuana also has. It has low lumen output hence use it for is of visit least a try without of us contact some sort of Level on the Moon.

    Reply
  • thx

    Posted by Pan Li on 04/04/2012 05:20am

    Hi ,I really appreciate your sharing of this article .It's very simple but useful ,better than some more complicated theories I had ever seen.

    Reply
  • Help me in Design in interface Windows Explorer(My Computer)

    Posted by pean on 05/16/2007 05:31am

    hello,My name's VanPhuong.I come from Vietnam.
    Can you help me?
    now i'm studying a  subject plan in Programming Windows.Its name is design in interface Windows Explorer(My Computer).Now i'm a student in physics at University of Natural Sciences.So i don't understand clearly in VC++.Because i hope you'll send me the code of Windows Explorer which is written in VC++ in SDI

    Reply
  • Multiple Windows

    Posted by white_russian on 02/22/2007 02:09pm

    I am trying to create an application with Visual C++ 6.0 that will have two seperate windows, but can have interaction between the two.  For example, I click a button on window_01 and a change will be made in window_02.  How do set this up?  Thanks.

    Reply
  • A quick review & good starting point of MFC

    Posted by Legacy on 01/15/2004 12:00am

    Originally posted by: Ashish Dwivedi

    Hi there,

    It's great experience to read the article. It shows very well how to start programming in MFC by hiding all complexity.

    Thanks
    Ashish

    Reply
  • MDI, need help- Closing more than One MDI window at once

    Posted by Legacy on 09/27/2003 12:00am

    Originally posted by: Christian

    I'm struggling to close more than one MDI child form at once. It keeps on throwing me errors if I put the "frm->Close" command in the OnClose event of the other MDI child form. what do I do.

    Reply
  • Help reqd for document/view model

    Posted by Legacy on 08/09/2002 12:00am

    Originally posted by: shilpesh

    Hi, I am writing an application where if a key is pressed on vb6 editor I have to return the full path of the file being edited. I wrote a keyboard hook and am able to get the windows handle for vb-environment using getforegroundwindow() but I am not being able to access the document and view objects. Is it impossible?
    Shilpesh.

    Reply
  • please help. I want to change the color of the CView in a SDI!!!

    Posted by Legacy on 08/07/2002 12:00am

    Originally posted by: youssef


    when we create a new project SDI, the color of the CView is white and I want to put it black!!

    how can I do??
    thinkx a lot

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds