Back to description
Windows programming isn't difficult. In fact, Microsoft Visual C++ 2008 makes it remarkably easy, as you'll see throughout... more
Windows programming isn't difficult. In fact, Microsoft Visual C++ 2008 makes it remarkably easy, as you'll see throughout the course of this book. There's just one obstacle in your path: Before you get to the specifics of Windows programming, you have to be thoroughly familiar with the capabilities of the C++ programming language, particularly the object-oriented aspects of the language. Object-oriented techniques are central to the effectiveness of all the tools that are provided by Visual C++ 2008 for Windows programming, so it's essential that you gain a good understanding of them. That's exactly what this book provides.
This chapter gives you an overview of the essential concepts involved in programming applications in C++. You'll take a rapid tour of the Integrated Development Environment (IDE) that comes with Visual C++ 2008. The IDE is straightforward and generally intuitive in its operation, so you'll be able to pick up most of it as you go along. The best approach to getting familiar with it is to work through the process of creating, compiling, and executing a simple program. By the end of this chapter, you will have learned:
What the principal components of Visual C++ 2008 are
What the .NET Framework consists of and the advantages it offers
What solutions and projects are and how you create them
About console programs
How to create and edit a program
How to compile, link, and execute C++ console programs
How to create and execute basic Windows programs
So power up your PC, start Windows, load the mighty Visual C++ 2008, and begin your journey.
... less
In this chapter, you'll get down to the essentials of programming in C++. By the end of the chapter you'll be able to write... more
In this chapter, you'll get down to the essentials of programming in C++. By the end of the chapter you'll be able to write a simple C++ program of the traditional form: input-process-output. As I said in the previous chapter, I'll first discuss the ANSI/ISO C++ language features and then cover any additional or different aspects of the C++/CLI language.
As you explore aspects of the language using working examples, you'll have an opportunity to get some additional practice with the Visual C++ Development Environment. You should create a project for each of the examples before you build and execute them. Remember that when you are defining projects in this chapter and the following chapters through to Chapter 11, they are all console applications.
In this chapter you will learn about:
C++ program structure
Namespaces
Variables in C++
Defining variables and constants
Basic input from the keyboard and output to the screen
Performing arithmetic calculations
Casting operands
Variable scope
In this chapter, you will look at how to add decision-making capabilities to your C++ programs. You'll also learn how to... more
In this chapter, you will look at how to add decision-making capabilities to your C++ programs. You'll also learn how to make your programs repeat a set of actions until a specific condition is met. This will enable you to handle variable amounts of input, as well as make validity checks on the data that you read in. You will also be able to write programs that can adapt their actions depending on the input data and to deal with problems where logic is fundamental to the solution. By the end of this chapter, you will have learned:
How to compare data values
How to alter the sequence of program execution based on the result
How to apply logical operators and expressions
How to deal with multiple choice situations
How to write and use loops in your programs
I'll start with one of the most powerful and fundamental tools in programming: the ability to compare variables and expressions with other variables and expressions and, based on the outcome, execute one set of statements or another.
So far, you have covered all the fundamental data types of consequence and you have a basic knowledge of how to perform calculations... more
So far, you have covered all the fundamental data types of consequence and you have a basic knowledge of how to perform calculations and make decisions in a program. This chapter is about broadening the application of the basic programming techniques that you have learned so far, from using single items of data to working with whole collections of data items. In this chapter, you will learn about:
Arrays and how you use them
How to declare and initialize arrays of different types
How to declare and use multidimensional arrays
Pointers and how you use them
How to declare and initialize pointers of different types
The relationship between arrays and pointers
References, how they are declared, and some initial ideas on their uses
How to allocate memory for variables dynamically in a native C++ program
How dynamic memory allocation works in a Common Language Runtime (CLR) program
Tracking handles and tracking references and why you need them in a CLR program
How to work with strings and arrays in C++/CLI programs
What interior pointers are and how you can create and use them
In this chapter you'll be using objects more extensively although you have not yet explored the details of how they are created so don't worry if everything is not completely clear. You'll learn about classes and objects in detail starting in Chapter 7.
Up to now, you haven't really been able to structure your program code in a modular fashion because you have only been able... more
Up to now, you haven't really been able to structure your program code in a modular fashion because you have only been able to construct a program as a single function, main(); but you have been using library functions of various kinds as well as functions belonging to objects. Whenever you write a C++ program, you should have a modular structure in mind from the outset and, as you'll see, a good understanding of how to implement functions is essential to object-oriented programming in C++. In this chapter, you'll learn:
main()
How to declare and write your own C++ functions
How function arguments are defined and used
How arrays can be passed to and from a function
What pass-by-value means
How to pass pointers to functions
How to use references as function arguments, and what pass-by-reference means
How the const modifier affects function arguments
const
How to return values from a function
How recursion can be used
There's quite a lot to structuring your C++ programs, so to avoid indigestion, you won't try to swallow the whole thing in one gulp. After you have chewed over and gotten the full flavor of these morsels, you'll move on to the next chapter, where you will get further into the meat of the topic.
In the previous chapter, you learned about the basics of defining functions and the various ways in which data can be passed... more
In the previous chapter, you learned about the basics of defining functions and the various ways in which data can be passed to a function. You also saw how results are returned to a calling program.
In this chapter, you will explore the further aspects of how functions can be put to good use, including:
What a pointer to a function is
How to define and use pointers to functions
How to define and use arrays of pointers to functions
What an exception is and how to write exception handlers that deal with them
How to write multiple functions with a single name to handle different kinds of data automatically
What function templates are and how you define and use them
How to write a substantial native C++ program example using several functions
What generic functions are in C++/CLI
How to write a substantial C++/CLI program example using several functions
This chapter is about creating your own data types to suit your particular problem. It's also about creating objects, the... more
This chapter is about creating your own data types to suit your particular problem. It's also about creating objects, the building blocks of object-oriented programming. An object can seem a bit mysterious to the uninitiated but, as you will see in this chapter, an object can be just an instance of one of your own data types.
In this chapter, you will learn about:
Structures and how they are used
Classes and how they are used
The basic components of a class and how you define class types
Creating and using objects of a class
Controlling access to members of a class
Constructors and how to create them
The default constructor
References in the context of classes
The copy constructor and how it is implemented
How C++/CLI classes differ from native C++ classes
Properties in a C++/CLI class and how you define and use them
Literal fields and how you define and use them
initonly fields and how you define and use them
What a static constructor is
In this chapter, you will extend your knowledge of classes by understanding how you can make your class objects work more... more
In this chapter, you will extend your knowledge of classes by understanding how you can make your class objects work more like the basic types in C++. You will learn:
What a class destructor is and when and why it is necessary
How to implement a class destructor
How to allocate data members of a native C++ class in the free store and how to delete them when they are no longer required
When you must write a copy constructor for a class
What a union is and how it can be used
How to make objects of your class work with C++ operators such as + or *
+
*
What class templates are and how you define and use them
How to use the standard string class for string operations in native C++ programs
string
How to overload operators in C++/CLI classes
In this chapter, you're going to look into a topic that lies at the heart of object-oriented programming... more
In this chapter, you're going to look into a topic that lies at the heart of object-oriented programming class inheritance. Simply put, inheritance is the means by which you can define a new class in terms of one you already have. This is fundamental to programming in C++ so it's important that you understand how inheritance works.
How inheritance fits into the idea of object-oriented programming
Defining a new class in terms of an existing one
The use of the protected keyword to define a new access specification for class members
protected
How a class can be a friend to another class
Virtual functions and how you can use them
Pure virtual functions
Abstract classes
Virtual destructors and when to use them
At its name implies, the Standard Template Library (STL) is a library of standard class and function templates. You can use... more
At its name implies, the Standard Template Library (STL) is a library of standard class and function templates. You can use these templates to create a wide range of powerful general-purpose classes for organizing your data as well as functions for processing that data in various ways. The STL is defined by the standard for native C++ and is therefore always available with a conforming compiler. Because of its broad applicability, the STL can greatly simplify programming in many of your C++ applications.
Of course, the STL for native C++ does not work with C++/CLI class types but in Visual C++ 2008 you have an additional version of the STL available that contains templates and generic functions that you can instantiate with C++/CLI class types.
In this chapter you will learn:
What capabilities are offered by the STL
What containers are and how you create and use them
What iterators are and how you use them with containers
The types of algorithms that are available with the STL and how you can apply the more common ones
What function objects are and how they are used with the STL
How to use the STL version that supports C++/CLI class types
If you have been doing the exercises in the previous chapters, you have most likely been battling with bugs in your code.... more
If you have been doing the exercises in the previous chapters, you have most likely been battling with bugs in your code. In this chapter you will explore how the basic debugging capabilities built into Visual C++ 2008 can help with this. You will also investigate some additional tools that you can use to find and eliminate errors from your programs, and see some of the ways in which you can equip your programs with specific code to check for errors.
How to run your program under the control of the Visual C++ 2008 debugger
How to step through your program a statement at a time
How to monitor or change the values of variables in your programs
How to monitor the value of an expression in your program
The call stack
Assertions and how to use them to check your code
How to add debugging specific code to a program
How to detect memory leaks in a native C++ program
How to use the execution tracing facilities and generate debugging output in C++/CLI programs
In this chapter, you take a look at the basic ideas that are involved in every Windows program in C++. You'll first develop... more
In this chapter, you take a look at the basic ideas that are involved in every Windows program in C++. You'll first develop a very simple example that uses the Windows operating system API directly. This will enable you to understand how a Windows application works behinds the scenes, which will be useful to you when you are developing applications using the more sophisticated facilities provided by Visual C++ 2008. You then see what you get when you create a Windows program using the Microsoft Foundation Classes, better known as the MFC. Finally, you'll create a basic program using Windows Forms that will execute with the CLR, so by the end of the chapter you'll have an idea of what each of the three approaches to developing a Windows application involves.
By the end of this chapter, you will have learned about:
The basic structure of a window
The Windows API is and how it is used
Windows messages and how you deal with them
The notation that is commonly used in Windows programs
The basic structure of a Windows program
How you create an elementary program using the Windows API and how it works
Microsoft Foundation Classes
The basic elements of an MFC-based program
Windows Forms
The basic elements of a Windows Forms application
In this chapter, you start down the road of serious Windows application development using the MFC. You'll get an appreciation... more
In this chapter, you start down the road of serious Windows application development using the MFC. You'll get an appreciation of what code the Application wizard generates for a Microsoft Foundation Class (MFC) program and what options you have for the features to be included in your code.
How Single Document Interface (SDI) applications and Multiple Document Interface (MDI) applications differ
How to use the MFC Application wizard to generate SDI and MDI programs
What files are generated by the MFC Application wizard and what their contents are
How an MFC Application wizard-generated program is structured
The key classes in an MFC Application Wizard-generated program, and how they are interconnected
The general approach to customizing an MFC Application wizard-generated program
You'll be expanding the programs that you generate in this chapter by adding features and code incrementally in subsequent chapters. You will eventually end up with a sizable, working Windows program that incorporates almost all the basic user interface programming techniques you will have learned along the way.
In the last chapter, you saw how a simple framework application generated by the MFC Application Wizard is made up and how... more
In the last chapter, you saw how a simple framework application generated by the MFC Application Wizard is made up and how the parts interrelate. In this chapter, you'll start customizing a Multiple Document Interface (MDI) framework application called Sketcher with a view to making it into a useful program. The first step in this process is to understand how menus are defined in Visual C++ 2008, and how functions are created to service the application-specific menu items that you add to your program. You'll also see how to add toolbar buttons to the application. By the end of this chapter, you'll have learned about:
How an MFC-based program handles messages
Menu resources, and how you can create and modify them
Menu properties, and how you can create and modify them
How to create a function to service the message generated when a menu item is selected
How to add handlers to update menu properties
How to add toolbar buttons and associate them with existing menu items
In this chapter, you will add some meat to the Sketcher application. You’ll focus on understanding how you get graphical... more
In this chapter, you will add some meat to the Sketcher application. You’ll focus on understanding how you get graphical output displayed in the application window. By the end of this chapter, you’ll be able to draw all but one of the elements for which you have added menu items. I’ll leave the problem of how to store them in a document until the next chapter. In this chapter, you will learn about:
What coordinate systems Windows provides for drawing in a window
Device context and why it is necessary
How and when your program draws in a window
How to define handlers for mouse messages
How to define your own shape classes
How to program the mouse to draw your shapes in a window
How to get your program to capture the mouse
In this chapter, you'll look into the facilities offered by MFC for managing collections of data items; these are similar... more
In this chapter, you'll look into the facilities offered by MFC for managing collections of data items; these are similar to the STL containers discussed in Chapter 10. You'll use the MFC collection classes to complete the class definition and implementation for the curve element that was left open in MFC Sketcher in the last chapter. You'll extend the MFC Sketcher to make the document view more flexible, introducing several new techniques in the process. You'll also extend the MFC and CLR versions of Sketcher to store elements in an object that encapsulates a complete sketch.
In this chapter, you'll learn about:
MFC collections and what you can do with them
How to use an MFC List collection and an STL/CLR vector container to store point data for a curve
How to use an MFC List collection and an STL/CLR list container to store sketch data
How to implement drawing a sketch in the MFC and CLR versions of Sketcher
How to implement scrolling in a view in MFC Sketcher
How to create a context menu at the cursor
How to highlight the element nearest the cursor to provide feedback to the user for moving and deleting elements
How to program the mouse to move and delete elements
Dialogs and controls are basic tools for user communications in the Windows environment. In this chapter, you'll learn how... more
Dialogs and controls are basic tools for user communications in the Windows environment. In this chapter, you'll learn how to implement dialogs and controls by applying them to extend the Sketcher program. As you do so, you'll learn about:
Dialogs and how you can create dialog resources
Controls are and how to add them to a dialog
Basic varieties of controls available to you
How to create a dialog class to manage a dialog
How to program the creation of a dialog box and how to get information back from the controls in it
Modal and modeless dialogs
How to implement and use direct data exchange and validation with controls
How to implement view scaling
How you can add a status bar to an application
With what you have accomplished so far in the Sketcher program, you can create a reasonably comprehensive document with views... more
With what you have accomplished so far in the Sketcher program, you can create a reasonably comprehensive document with views at various scales, but the information is transient because you have no means of saving a document. In this chapter, you'll remedy that by seeing how you can store a document on disk. You'll also investigate how you can output a document to a printer.
Serialization and how it works
How to make objects of a class serializable
The role of a CArchive object in serialization
CArchive
How to implement serialization in your own classes
How to implement serialization in the Sketcher application
How printing works with MFC
What view class functions you can use to support printing
What a CPrintInfo object contains and how it's used in the printing process
CPrintInfo
How to implement multipage printing in the Sketcher application
Chapter 9 discussed how a C++/CLI class library is stored in a... more
Chapter 9 discussed how a C++/CLI class library is stored in a .dll file. Dynamic link libraries (DLLs) are also used extensively with native C++ applications. A complete discussion of DLLs in native C++ applications is outside the scope of a beginner's book, but they are important enough to justify including an introductory chapter on them. In this chapter, you will learn about:
.dll
DLLs and how they work
When you should consider implementing a DLL
What varieties of DLL are possible and what they are used for
How you can extend MFC using a DLL
How to define what is accessible in a DLL
How to access the contents of a DLL in your programs
In this chapter, I will show you to how you can interface to a database using Visual C++ and the MFC and access the data... more
In this chapter, I will show you to how you can interface to a database using Visual C++ and the MFC and access the data from it. This is by no means a comprehensive discussion of the possibilities, because a full discussion of database application development using Visual C++ would occupy a very substantial book in its own right. In this chapter, however, you will look at how you can read from a database in this chapter, and in the next chapter you will explore the basics of how you can update a database. Of course, you can access data sources in CLR applications, and you’ll look at this in Chapter 23.
SQL and how it is used
How to retrieve data using the SQL SELECT operation
SELECT
What database services are supported by MFC
What a recordset object is, and how it links to a relational database table
How a recordset object can retrieve information from a database
How a record view can display information from a recordset
How to create a project for a database program
How to add recordsets to your program
How to handle multiple record views
In this chapter, you'll build on what you learned about accessing a database via ODBC (Open DataBase... more
In this chapter, you'll build on what you learned about accessing a database via ODBC (Open DataBase Connectivity) in the previous chapter, and try your hand at updating the Northwind Traders database through the same mechanism.
Database transactions
How to update a database using recordset objects
How data is transferred from a recordset to the database in an update operation
How to update an existing row in a table
How to add a new row to a table
You already know quite a lot about the process of creating Windows Forms applications from CLR Sketcher. In this chapter,... more
You already know quite a lot about the process of creating Windows Forms applications from CLR Sketcher. In this chapter, you will explore some more controls that you can use in the GUI for a Windows Forms application. You'll do this by assembling a single application incrementally throughout the chapter, so by the end of the chapter you'll have another Windows Forms program of a reasonable size.
In this chapter, you'll learn:
How to use a wider variety of controls to build an application GUI
How to display a Web page in an application
How to work with control containers
How to create and display message boxes
In this chapter, you'll investigate how you can develop form-based applications that will display data from a variety of... more
In this chapter, you'll investigate how you can develop form-based applications that will display data from a variety of sources and specifically how you can create form-based programs to access an existing database. In this chapter, you will learn about:
What kind of classes are involved in encapsulating a data source
How you can use the DataGridView control to display your own data
DataGridView
How you can customize the appearance of a DataGridView control
What the function of the BindingSource component is and how you use it with a DataGridView control
BindingSource
How you use a BindingNavigator control to navigate data from a source managed by a BindingSource control
BindingNavigator
How you expedite updating of a database using a BindingNavigator control and a BindingSource component
Note
Visual C++ 2008 provides a high degree of automation for creating Forms-based applications that access data sources but you will start by ignoring the automation and get a feel for how you can work with components programmatically. With this approach, you'll not only get a good insight into how things work; you'll also appreciate how much the automation is doing for you.
Keywords have been assigned special significance within the C++ language, so you must not use them as names within your programs... more
Keywords have been assigned special significance within the C++ language, so you must not use them as names within your programs. The Visual C++ 2008 compiler compiles programs written in ISO/ANSI C++ and programs written for the CLR that conform to the C++/CLI specification, so the compiler recognizes the set of keywords defined by ISO/ANSI C++ as well as the additional set of keywords defined by C++/CLI. Although programming in native C++, you need be concerned only with the ISO/ANSI C++ keywords. When writing programs for the CLR, you need to be aware of both sets of keywords.
The first 32 ASCII (American Standard Code for Information Interchange) characters provide control functions. In the following... more
The first 32 ASCII (American Standard Code for Information Interchange) characters provide control functions. In the following table, only the first 128 ASCII characters have been included. The remaining 128 characters include further special symbols and letters for national character sets, so there are many varieties of these to suit a wide range of language contexts.
The Windows operating system defines the type of system message that it sends to your application by a symbolic constant... more
The Windows operating system defines the type of system message that it sends to your application by a symbolic constant such as WM_PAINT. The symbolic constant is composed of two parts, a prefix, WM in this case, that identifies the type of window that can process the message, and the rest, PAINT in this case, that specifies what the window should do when the message is received. The following table shows the message prefixes and the corresponding target window category.
WM_PAINT
WM
PAINT
Purchase Before purchasing this product, please be sure you have met all software and system requirements, and that you understand any limits placed upon its use.
Return Policy Wrox Chapters on Demand are non-returnable and non-refundable.
Reader Software Wrox Chapters on Demand are offered as PDFs, and they must be viewed using the Adobe Reader. If you do not have the Reader installed, it can be downloaded for free at Adobe.com.
Test Download As Wrox Chapters on Demand purchases are non-returnable, it is advisable that you test your system and software configurations with a free sample download before you place an order.
Usage Rights for a Wrox Chapter on Demand File Any Wrox Chapter on Demand product you purchase from this site will come with certain restrictions that allow Wiley to protect the copyrights of its products. After you purchase and download this title, you:
If you have any questions about these restrictions, you may contact Customer Care at (877) 762-2974 (8 a.m. - 5 p.m. EST, Monday - Friday). If you have any issues related to Technical Support, please contact us at 800-762-2974 (United States only) or 317-572-3994 (International) 8 a.m. - 8 p.m. EST, Monday - Friday).
Related Books