Datasheet

Book VII
Chapter 1
Working with the
Visual C++ 2008 IDE
and Projects
719
Creating a New Win32 Console Application
Adding code
One of the first things you must decide is which version of Windows to
target with your application. Open the targetver.h file and you’ll see an
explanation of its purpose. Microsoft always assumes that you’ll want to
target the latest version of Windows and will ignore anything older, which
isn’t a reasonable approach. Consequently, you normally need to change
this file to match the version of Windows you want to work with. All you
need to do is change the version number as shown here:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
Using a version number of 0x0501 means that you’re targeting Windows
XP. If you’d wanted to target Windows 2000, you would have used a value of
0x0500. Windows Server 2003 uses a version number value of 0x0502.
The application will use standard input and output functionality, so you
need to open the stdafx.h file next. You might wonder why Microsoft uses
this separate file to store headers. Using a centralized location for declara-
tions you plan to use for the entire application makes sense because you
need to make changes only once. To the standard header declarations, you
add #include <iostream> as shown here:
#pragma once
#include “targetver.h”
#include <stdio.h>
#include <tchar.h>
#include <iostream>
It’s time to add the code to the Hello World.cpp file. Here’s the simple
code used for this example:
#include “stdafx.h”
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// Display the message.
cout << “Hello World!” << endl;
// Pause so you can see it in the debugger.
system(“PAUSE”);
return 0;
}
44_317358-bk07ch01.indd 71944_317358-bk07ch01.indd 719 7/22/09 11:44:51 PM7/22/09 11:44:51 PM