Doc View Less Work for You

[Previous] [Next]

As you play around with SdiSquares, notice how much of the application's functionality is provided by MFC. For example, documents can be opened and saved, despite the fact that we added a mere eight lines of code in support of such operations. If you change the color of a square and attempt to open another document or exit the application, a message box appears asking if you'd like to save your changes first. Double-clicking an SdiSquares document file in the operating system shell automatically starts SdiSquares and loads the document. MFC provides these features and more because we built the application using documents and views. You'll see other benefits of using the document/view architecture in chapters to come.

The first time I ever looked at a minimal MFC application generated by AppWizard, I was dumbfounded by how relatively little code there was. What I didn't realize at the time was that the framework provided entire chunks of the application by way of innocent-looking message-map entries like this one:

 ON_COMMAND (ID_FILE_OPEN, CWinApp::OnFileNew) 

Still other parts of the program (notably the File menu's Save and Save As commands) were also implemented by the framework but weren't even visible as message-map entries because the message mapping was performed in the base class. All in all, it looked as if a lot of magic was going on, and it was clear to me that I was going to have to do some digging before I would fully understand the mechanics of doc/view.

As I soon found out, there's nothing magic about the document/view architecture—just some clever coding hidden in preprocessor macros and thousands of lines of code written to handle routine (and not-so-routine) chores such as resizing a view when a frame window is resized and carrying on DDE conversations with the shell. Many programmers fail to see the big picture because they don't take the time to look under the hood at the code AppWizard generates for them. SdiSquares is a document/view application in existential form, unobscured by nonessential extras. If you understand SdiSquares, you're well on your way to understanding the document/view architecture.



Programming Windows with MFC
Programming Windows with MFC, Second Edition
ISBN: 1572316950
EAN: 2147483647
Year: 1999
Pages: 101
Authors: Jeff Prosise

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net