|
 |
 |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
(Publisher: John Wiley & Sons, Inc.)
Author(s): Steve Holzner
ISBN: 0471312908
Publication Date: 09/01/98
Chapter 1 Up to Speed in Visual C++
Welcome to our book on Visual C++. This book begins where introductory books on Visual C++ stop. In this book, we get into Visual C++ and push it as far as it will go. We work from intermediate Visual C++ all the way through truly advanced topics, putting this powerful package to work for us.
Theres little doubt that Visual C++ is the premiere programming package for serious Windows programmers today. Theres simply no other widely distributed package that can compare in terms of programming depth, strength, and extent. If you can do it in Windows programming, you can do it in Visual C++.
The sheer scope of Visual C++ frequently means that programmers remain ignorant of whats available to them, and its no wonder, given the difficulty of finding and becoming familiar with the various aspects of Visual C++ programming. Thats where this book comes into play. Were going on a guided tour of Visual C++, from the intermediate level up through the advanced level.
We start with intermediate topics such as the ins and outs of MDI and menus, as well as how to use different kinds of windows from the Microsoft Foundation Classes (MFC) arsenal: splitter windows, HTML windows, edit windows, and more. Then we put all those aspects of Visual C++ programming together in real-world applications.
From there, we increase our Visual C++ power with graphics work such as screen capture and working with metafiles, 32-bit memory handling such as process-to-process communication, connecting to the Internet and building a full Web browser, working with multithreaded programs, using Windows hooks, creating DLLs, working with OLE and COM, working with the Windows Registry, creating ActiveX controls, and much more.
We start our Visual C++ guided tour in this chapter, where we review the basics of Visual C++, laying the foundation for the rest of the book. This review makes sure were up to speed. The review begins with an overview of Visual C++ and its place in the programming pantheon.
Why Visual C++?
When Windows first appeared on the scene, only Microsoft produced Windows programs. All such programs were created using the proprietary Microsoft Windows libraries, which were not accessible to outside programmers. Pressure from programmers made Microsoft assemble the Windows Software Development Kit (SDK) and release that collection of libraries to the public.
Many programmers were appalled by the Windows SDK in those early days. It turned out that creating Windows programs meant creating long, involved programs in C using weak programming practices, such as the notorious multipage switch statement, which formed the backbone of the entire program, and learning about a thousand new library routines. The learning curve was steep, and many programmers failed to make the ascent.
Windows programming was first done in C, and Windows programs were long. As it turns out, C++ was developed expressly to handle longer programming tasks, so C++ was a natural for Windows programming.
C++ and Windows
C++ allows programmers to divide longer programming tasks through the process of encapsulation, which means breaking programming tasks into logical and functional units that are easily thought of and easily handled.
Through encapsulation, you combine program code and data into programming objects, and the program is broken up into these semi-independent objects that interact with each other in specifically defined ways. This process of encapsulation is much the same way one handles any complex task. For example, when driving somewhere, you dont want to be bothered with all the details of gasoline flow, ignition timing, differential power drive, and so on; you just want to get in you car and go. Because all the details are handled for you, you end up with an easily thought of objecta carthat has a specific purpose and handles all the details itself internally. In the same way, C++ allows the programmer to break a programming task into functions and data to divide the programming task into logical units that best solve the problem. For example, an object named screen may contain all the functions that handle the screen: Some of these functions are public to the rest of the program, and some are private to the object, handling the objects internal data in a way that hides the details and makes the entire program easier to handle.
Because of C++s ability to work with the large Windows programs, several vendors appeared with C++ Windows programming packages, and in time Microsoft produced Visual C++. Visual C++ was much more than just C++ for Windows, however, because it also included the Microsoft Foundation Class library. In addition to encapsulation, C++ also supports inheritance, allowing programmers to derive one class from another, and the MFC takes advantage of inheritance to give programmers literally hundreds of foundation classes on which to build their own classes. Microsoft has provided us with thousands of lines of prewritten code that we can use through inheritance. For example, if we want to create a splitter window (a window you can split into two independently scrollable panes), you just use the CSplitterWnd class as the base class of your own window class, and youve inherited all the functionality of that class. All you need to do is to tailor your new class the way you want it, and youre set. Microsoft has done the hard work for us, which is fortunate, because theres a lot of hard work to do in Windows programming.
With Visual C++, Windows programming had really begun, because programmers now had a viable programming tool. In time, Visual C++ has grown into an extensive programming environment, rich in tools and capabilities. This book explores what Visual C++ has to offer.
We will continue our guided tour of Visual C++ now with our review of Visual C++ programming to make sure we have a firm foundation for the rest of our book.
To get started, well create two sample programs in this chapter: one based on dialog windows, and one based on the Single Document Interface (SDI). In the next chapter, well expand our horizons by digging into the Multiple Document Interface (MDI). Lets start now with our first example program, HelloDlg.
|