- Shopping Bag ( 0 items )
The purpose of the book is to give novices the knowledge to begin using Visual C++ 6 at a low price point without sacraficing the content or quality. The proven elements of the Teach Yourself in 24 hours series make this book the most efficient way to learn Visual C++.Teach Yourself Visual C++ 6 in 24 Hours teaches the reader how to program Visual C++ applications in 24 lessons that can each be completed in about an hour each.Users will learn Visual C++ through the elements of the Teach Yourself series. Readers ...
The purpose of the book is to give novices the knowledge to begin using Visual C++ 6 at a low price point without sacraficing the content or quality. The proven elements of the Teach Yourself in 24 hours series make this book the most efficient way to learn Visual C++.Teach Yourself Visual C++ 6 in 24 Hours teaches the reader how to program Visual C++ applications in 24 lessons that can each be completed in about an hour each.Users will learn Visual C++ through the elements of the Teach Yourself series. Readers can look forward to learning about all of the various components of Visuall C++, the Developer Studio, creating C++ probrams, Property Pages and Property Sheets, Object-oriented design, and more.
I. GETTING STARTED WITH VISUAL C++ 6.
HOUR 1. Using Visual C++ 6.
Exploring Visual C++ 6. Starting Developer Studio. Creating Your First C++ Program. Creating a Windows Program Using AppWizard. Summary. Q&A. Workshop.
HOUR 2. Writing Simple C++ Programs.
The Common Elements of a C++ Program. A Simple C++ Program. Summary. Q&A. Workshop.
HOUR 3. Functions, Structures, and Classes.
What Are Statements and Expressions Using Functions? What Are Structures? What Are Classes? Rectangles and Regions. Summary. Q&A. Workshop.
II. DIALOG BOXES AND BASIC CONTROLS.
HOUR 4. Using Dialog Boxes.
What Is a Dialog Box? Using Dialog Boxes for Input. Creating Dialog Boxes in Visual C++. Creating Dialog Box-Based Projects. Summary. Q&A. Workshop.
HOUR 5. Button Controls.
What Is a Button? Associating Member Variables with a Button Control. Controlling Your Program with Conditional Expressions. Enabling and Disabling Buttons. Hiding a Button. Defining and Setting Tab Order. Summary. Q&A. Workshop.
HOUR 6. Using Edit Controls.
Understanding Edit Controls. Edit Control Properties. Binding a CEdit Object to an Edit Control. Collecting Entered Text from an Edit Control. Passing Parameters to Dialog Boxes Using DDV and DDX Routines. Summary. Q&A. Workshop.
HOUR 7. Using List Box and Combo Box Controls.
What Are List Boxes? Adding a List Box to a Dialog Box. What Are Combo Boxes? Using Loops. Summary. Q&A. Workshop.
III. WINDOWS AND MFC ARCHITECTURE.
HOUR 8. Messages and Event-Driven Programming.
Understanding the Windows Programming Model. What Are Messages? A Program to Test for Mouse Clicks. Handling Messages with ClassWizard. What Are MFC Base Classes? Summary. Q&A. Workshop.
HOUR 9. The Document/View Architecture.
Visual C++ Support for Document/View. Pointers and References. Exploring Document/View Interfaces. Summary. Q&A. Workshop.
HOUR 10. Menus.
What Is a Menu? Creating a Menu. Adding New Menu Items. Creating a Shortcut Menu. Using Keyboard Accelerators. Summary. Q&A. Workshop.
IV. THE GRAPHICS INTERFACE.
HOUR 11. Device Contexts.
What Are Device Contexts? How to Use Device Contexts. Stock Objects. Setting the Device Context Map Mode. A Device Context Example. Using Color in Windows Applications. Summary. Q&A. Workshop.
HOUR 12. Using Pens and Brushes.
What Is a Pen? Drawing with Pens. What Are Brushes? Summary. Q&A. Workshop.
HOUR 13. Fonts.
What Are Fonts? Specifying Font Attributes. Examples of Creating Fonts Using MFC. Selecting and Configuring the Right Fonts. Programming Fonts. Summary. Q&A. Workshop.
HOUR 14. Icons and Cursors.
What Is an Icon? Creating Icons Using the Image Editor. What Is a Cursor? Using Cursors in Windows Programs. Summary. Q&A. Workshop.
V. COMMON CONTROLS.
HOUR 15. Spin, Progress, and Slider Controls.
The Common Controls. The Spin Control. Using the Slider Control. Using the Progress Control. Summary. Q&A. Workshop.
HOUR 16. Using Bitmaps and Image Lists.
What Is a Bitmap? What Is an Image List? Using an Image List. Summary. Q&A. Workshop.
HOUR 17. List View Controls.
What Is a List View Control? List View Control Properties. Using a List View Control. Summary. Q&A. Workshop.
HOUR 18. Tree Views.
What Is a Tree View Control? MFC Support for Tree View Controls. Using a Tree View Control as a View. Adding Tree View Controls to Dialog Boxes. Deleting Items from a Tree View Control. Performing In-Place Label Editing. Summary. Q&A. Workshop.
HOUR 19. Using ActiveX Controls.
What Is an ActiveX Control? Why Use an ActiveX Control? How Is an ActiveX Control Used? An Example Using an ActiveX Custom Control. Summary. Q&A. Workshop.
VI. ADVANCED MFC PROGRAMMING.
HOUR 20. Dynamic HTML.
What Is Dynamic HTML? Visual C++ Support for Dynamic HTML. Using MFC and Dynamic HTML. Summary. Q&A. Workshop.
HOUR 21. Printing.
What Is Printing in a Windows Program? Understanding the MFC Printing Routines. Querying the Printing Device Context. Adding Printing Functionality to the MFCPrint Example. Summary. Q&A. Workshop.
HOUR 22. Using MFC to Save Program Data.
What Are Persistence and Serialization? Why Use Serialization? A Document/View Serialization Example. How Are Document/View Applications Serialized? Summary. Q&A. Workshop.
HOUR 23. Form Views.
What Is a Form View? Using a Form View. Summary. Q&A. Workshop.
HOUR 24. Creating ActiveX Controls.
What Is an ActiveX Control? ActiveX Control Properties, Events, and Methods. Creating an ActiveX Control. Testing an ActiveX Control. Summary. Q&A. Workshop.
Appendix A: Quiz Answers.
Hour 1, "Using Visual C++ 6". Hour 2, "Writing Simple C++ Programs". Hour 3, "Functions, Structures, and Classes". Hour 4, "Using Dialog Boxes". Hour 5, "Button Controls". Hour 6, "Using Edit Controls". Hour 7, "Using List Box and Combo Box Controls". Hour 8, "Messages and Event-Driven Programming". Hour 9, "The Document/View Architecture". Hour 10, "Menus". Hour 11, "Device Contexts". Hour 12, "Using Pens and Brushes". Hour 13, "Fonts". Hour 14, "Icons and Cursors". Hour 15, "Spin, Progress, and Slider Controls". Hour 16, "Using Bitmaps and Image Lists". Hour 17, "List View Controls". Hour 18, "Tree Views". Hour 19, "Using ActiveX Controls". Hour 20, "Dynamic HTML". Hour 21, "Printing". Hour 22, "Using MFC to Save Program Data". Hour 23, "Form Views". Hour 24, "Creating ActiveX Controls".
Appendix B: The Developer Studio IDE.
Using Developer Studio's Dockable Windows. What Is the Developer Studio Editor? What Is the Microsoft Developer Network Library?
[Figures are not included in this sample chapter]
In the first two hours you've learned some of the basic concepts behind C++, and
you have written some simple programs. In this hour you will be introduced to some
more advanced Visual C++ programming topics. In particular, you will learn
You will also build sample programs that illustrate the topics you learn in this
Statements and expressions are the elements defined by the C++ language that are
converted into machine code by the compiler to build your C++ programs. Seems like
a textbook-type definition, doesn't it? In reality, though, defining exactly what
they are is difficult. When talking about a building, we can say that it is made
of bricks, boards, and other things; we can define the brick or board very easily.
In the case of the C++ programming language, it is much more difficult; here we are
dealing with abstract concepts. The difference between a statement and expression
is very subtle, as you will soon see. Although it appears to be confusing at first,
the language will become understandable with practice. Eventually the C++ language
will become as natural to you as your native language.
Just like the simple Hello programs, all C++ programs are made up of statements
and expressions. Expressions and statements range from the simple statements that
were shown in the Hello programs to very complex expressions that stretch across
All statements end with semicolons. In fact, the simplest statement is called
the null statement, and it consists of only a single semicolon, as follows:
The null statement isn't used often; it's used only in situations in which the
C++ syntax requires a statement, but no real work needs to be done.
You use a statement to tell the compiler to perform some type of specific action.
For example, you know from the console mode programs you created that the following
statement will display the characters Hello World! on your screen:
cout << "Hello World!" << endl;
A declaration is another type of statement. A declaration introduces a variable
to the compiler. The following line is an example of a simple declaration:
This tells the compiler that myAge is an integer.
An assignment expression is used to assign a value to a variable, using the assignment
operator, =, as follows:
myAge = 135;
Every expression has a value. The value of an assignment expression is the value
of the assignment. This means that the following statement assigns the value 42
to the variables yourAge and myAge:
myAge = yourAge = 42;
The program in Listing 3.1 demonstrates how to assign a value to a variable.
using namespace std;
myAge = 42;
cout << "Hello" << endl;
cout << "My age is " << myAge << endl;
The assignment operator is just one example of the operators available in C++.
More operators are discussed in the next section.
The C++ language contains operators that you can use to write addition, subtraction,
multiplication, and other expressions. Some common math operators are shown in Table
myAge = 40 + 2;
The expression 40 + 2 has a value of 42. After that value is
calculated, the value of the expression is stored in the myAge variable.
NEW TERM: A function is a group of computer instructions that performs
a well-defined task inside a computer program. Functions are one of the primary building
blocks of C and C++ applications. Functions provide a way to break up a large program
into more manageable parts. At the same time, functions make it possible to perform
the same task at various points within the program without repeating the code.
For example, if you buy a wagon you'll find that it comes with a full set of assembly
instructions and has four identical wheels. Why should the instructions repeat the
steps to assemble a wheel four times? It is much easier to describe the wheel assembly
process once and indicate that you perform the process for each wheel. The wheel
assembly instructions are a module (function) within the full set of assembly instructions
(program) that is executed four times.
Every C++ program has at least one function; this function is usually called main.
The main function is called by the operating system when your application
starts; when main has finished executing, your program has finished.
Most Windows programs written in C++ have a similar function named WinMain
that serves the same purpose as main in a console-mode program. In an MFC
program the WinMain function is part of the MFC library code--you will rarely
need to provide a WinMain function yourself.
Before you can use a function, you must declare it by supplying a function prototype
to the compiler. To declare a function you specify the function's name, its return
value, and a list of any parameters that are passed to it, as shown here:
int CalculateAge(int nYearBorn);
This line is a function prototype for the CalculateAge function, which
takes a single integer as a parameter and returns an integer as its result. A function
that returns no value is declared as returning the void type.
NEW TERM: The traditional way to provide function prototypes is to place
them in header files, which are usually named with an .h extension.
Header files that are part of the C++ standard library do not use the .h
extension; two examples of standard header files are iostream and math.
These header files contain all the prototypes and other declarations needed for IO
streams and math functions to be compiled correctly.
A function is defined the same way the main function is defined. All
function definitions follow the same pattern; it's basically the function prototype
with the function's body added to it. The function definition always consists of
Listing 3.2 shows how to use a function to display the Hello World! message. To
run this project, create a new console-mode project named HelloFunc, using
the steps described for the Hello and Hello2 projects in the first two hours.
using namespace std;
// Function prototype
void DisplayAge(int nAge);
void DisplayAge(int nAge)
cout << "Hello World! I'm " << nAge << " years old." << endl;
Because the function doesn't return a value to the calling function, the return
type is defined as void.
In the C++ language, the act of transferring control to a function is known as
calling the function. When a function is called, you supply a function name
and a list of parameters, if any. The following steps take place when a function
4. After the function has finished executing, control is returned to the
calling function and memory used by the function is released.These steps are shown
in Figure 3.1, which uses the function from Listing 3.1 as an example.
FIGURE 3.1. Steps involved in calling a function.
NOTE: The requirement that you declare functions before using them is an extension
of the C++ type system. Because function prototypes are required, the compiler can
detect errors such as incorrect parameters used in a function call.
NEW TERM: A structure is a data type that contains other data types
grouped together into a single user-defined type.
NOTE: Structures are commonly used when it makes sense to associate two or
more data variables.
An example of a structure is a payroll record, where the number of hours worked
and the pay rate are combined in a structure, as shown in Figure 3.2.
FIGURE 3.2. Structures are made up of member variables.
Declaring a structure introduces a new type of variable into your program. Variables
of this new type can be defined just like int, char, or float
variables are defined. Listing 3.3 is an example of how a structure is typically
using namespace std;
payrollRecord.dHours = 40.0;
payrollRecord.dRate = 3.75;
cout << "This week's payroll information:" << endl;
cout << "Hours worked : " << payrollRecord.dHours << endl;
cout << "Rate :$" << payrollRecord.dRate << endl;
double dSalary = payrollRecord.dRate * payrollRecord.dHours;
cout << "Salary :$" << dSalary << endl;
NEW TERM: A class allows data and functions to be bundled together
and used as if they were a single element. Classes typically model real-world concepts
that have both data and some sort of behavior, although this is not a hard and fast
NEW TERM: A function that is defined as part of a class is often called
Classes are similar to structures; in fact, classes really are just structures
with a different name. Classes have one feature that makes them very useful for object-oriented
programming: Unless a member of a class is specifically declared as public,
that member is generally not accessible from outside the class. This means that you
can hide the implementation of methods behind the external interface.
NOTE: Like functions, classes are an important part of the C++ programming
language. In fact, one of the earliest names for C++ was C with Classes.
NEW TERM: An instance of a class, sometimes called an object, is
an occurrence of a class. An instance of one of your classes can be used or manipulated
inside your programs.
When using Visual C++, objects such as dialog boxes, window frames, menus, and
buttons are controlled by C++ classes. A class is just a description of the object
that can be created and the actions that can be performed on it.
A C++ class has two main parts:
The data that makes up an object, and the functions that are performed on that
object, are combined to form a class, or a description of that object. Classes can
inherit functionality from other objects, and you easily can add new classes that
leverage existing classes.
Classes and instances of classes are not the same things. This can sometimes be
a confusing concept if you are new to C++ or object-oriented programming. Think of
a class as the description of an object; an instance of a class is a concrete occurrence
of that class.
NEW TERM: A constructor is a special member function that is created
when an object of the class is created. A constructor always has the same name as
the class and never has a return value, not even void. The purpose of the
constructor is to place a newly created object into a known state. Typically, constructors
can allocate system resources, clear or set variables, or perform some other type
NEW TERM: A destructor is a special member function that is called
as an object is destroyed. The destructor is declared as having no return type and
is never declared with a parameter list. The name of the destructor is the class
name prefixed by a tilde (~) character.
Defining a destructor is not necessary unless specific tasks must be performed
to clean up after an object, such as releasing system resources that might have been
As an example of a C++ class, let's look at a class that represents a weekly payroll
record. The class must have two member variables:
The class will also define three member functions that
The definition of a class is similar to that of a structure, except that the keyword
class is used instead of struct. Listing 3.4 provides a declaration
for a CWeeklyPayRecord class.
void HoursWorked( double dHours );
void PayRate( double dRate );
The keywords public and private are used to grant or deny access
to members of the class. Any members of the class declared after the public
keyword can be accessed from outside the class, just as though they were members
of a structure. Any members of the class declared after the private keyword
are not accessible outside the class. Any number of public or private
access specifiers can be present in a class declaration. The closest access specifier,
reading from top to bottom, is the one that is currently controlling a declaration.
Listing 3.5 is a complete example that uses the CWeeklyPayRecord class,
with some typical member functions added.
using namespace std;
void HoursWorked( double dHours );
void PayRate( double dRate );
// main - Create a weekly salary object, and calculate this
// week's salary.
weeklyPay.HoursWorked( 40.0 );
weeklyPay.PayRate( 3.75 );
cout << "This week's payroll information:" << endl;
cout << "Salary :$" << weeklyPay.GetSalary() << endl;
// Member functions for the CWeeklyPayRecord class
void CWeeklyPayRecord::HoursWorked( double dHours )
m_dHours = dHours;
void CWeeklyPayRecord::PayRate( double dRate )
m_dRate = dRate;
return m_dHours * m_dRate;
Note that the member functions in Listing 3.5 are prefixed with CWeeklyPayRecord::
when they are defined. The names of all member functions are prefixed with their
class names; this is the only way the compiler can determine to which class the function
belongs. The only exception to this rule is a function that is defined inside the
The rectangle is a fundamental component of most Windows programs. Because most
windows and controls are rectangular, it isn't surprising that one of the most commonly
used data structures in Windows programming is used to represent a rectangle.
Rectangles are often used to represent the position or size of all types of windows:
main windows as well as controls, toolbars, and dialog boxes. There are two basic
types of rectangle coordinates:
Screen rectangle coordinates are often used when moving a window in relation to
the entire screen. Client rectangles are most commonly used when positioning controls
or drawing inside a control or other window.
When requesting the dimensions of a rectangle, you must pass a CRect
variable to one of the Windows rectangle functions. The following two lines of code
declare an instance of CRect as a variable and pass it to the GetClientRect
The next example uses a client area rectangle to display a message to the user,
just like the HelloMFC program in the first hour. The new example will draw the message
in the center of the client area; if the window is resized, the message will be redrawn
in the center of the new rectangle.
Create an MFC AppWizard application named HelloRect, following the steps presented
in the first hour. Modify the OnDraw function found in the CHelloRectView
class so that it looks like the function shown in Listing 3.6.
void CHelloRectView::OnDraw(CDC* pDC)
pDC->DrawText("Hello Client Rectangle!", -1, rcClient,
DT_SINGLELINE | DT_CENTER | DT_VCENTER );
Build the HelloRect application and run it from Developer Studio. Note that if
you resize the window, the message is redrawn so that it remains in the center of
the client area.
In this hour you learned some of the more advanced building blocks that make up
C++ programs: functions, structures, and classes. As an example of how C++ classes
are used, a payroll class was created and used. The hour finished with a discussion
about rectangles and regions in Windows programs.
The Workshop is designed to help you anticipate possible questions, review what
you've learned, and begin thinking ahead to putting your knowledge into practice.
The answers to the quiz are in Appendix A, "Quiz Answers."
Posted May 26, 2000
The book was easy to read and had wery good examples. The text was readable, but the drawing were a little hard to see but if you can understand text it does not matter. It does help to know a little c++ before reading.Was this review helpful? Yes NoThank you for your feedback. Report this reviewThank you, this review has been flagged.
Posted February 12, 2000
First let me identify my profile: I knew my way around console C++ pretty well before reading this book, and had never touched windows programming, MFC, or VC++ before. The book turned out to have a rather low information-per-page ratio for my tastes, especially as it tried to teach basic C++ concepts (conditional statements, looping, etc). I understand that programming basics would be nice for a beginning programmer, but I imagine the treatment of basic C++ was too hurried for any beginning to try to learn it, especially since the pour souls would be practically learning OOP before they know how to write their own function. I think SAMS needs two make two version of this book- one for beginning programmers and one for windows programmers. The former could go more in-depth into basic programming constructs, while the latter could skip them altogether and use the extra space to add more meat regarding windows programming. I found myself getting more information from the MSDN than the book itself. I do have to give this book some credit- I learned what I needed to for programming VC++ at work- but I'll need another book or two before I'm anywhere near the level of, say, a MS certified VC++ desktop developer. All in all, not a total waste of money, but not completely satisfactory either.Was this review helpful? Yes NoThank you for your feedback. Report this reviewThank you, this review has been flagged.