VCPP 6.0 - TUTORIAL - LESSON #1 DHTML (c) Artur Marques, 01 June 1999
Next lesson [Lesson #2]
Everything that grows big, gets enemies. While you are small and don't make a noise, no one will notice you, so you won't have problems.
Nowadays, MICROSOFT is bigger than life. MICROSOFT is so big and powerful, that if feels the need to have some internal changes, towards the "small is beautiful" moto. This introduction comes because one of the most interesting MS products: the VISUAL C++ environment.
VCPP (Visual C Plus Plus) is the tool used to build most of today's superb software. Every major game, every major Windows application, will at the very least have some part of it developed in VCPP. Please have no doubt that the VCPP tool, is quite a technical achievement. Of course that MS, because it has grown so huge, has many people saying that things are NOT quite like I am writing... in fact, it is very easy to find people saying that MS stinks, no matter the software. These people look at games like "Age of Empires" and they say "it stinks"; these people look at a DTP tool such as "Publisher 2000", and they say "it does nothing good"... you get the picture. These people are radicals, and they deserve little respect.
I am neutral. During my very, VERY modest tutorials, I will try to call your attention to good, not so good, and even bad things about the VCPP world. And it is quite a world!
Where can we start to learn VCPP? This question is like facing a maze with 10000 entrances, and wonder "where shall I begin"? VCPP is bigger than that maze. VCPP will allow you to build from elementar console software to revolutionary programs, that may well shift some computer science paradigm. To start using VCPP, the very least that you need to know is the C language. This tutorial ASSUMES you know some C.
To be honest, I will be writing this tutorial, as I learn VCPP, in order to build a OpenGL 3D game with cars on it :-). Lets make this journey together! One thing: this journey will never end. VCPP keeps growing and I can assure you that NO ONE in the world knows half of what there is to know about VCPP. You may find someone with a perfect knowledge of C, C++ and its use in the win32 model, but then that person may not be as great with the MFC (MS Foundation Classes), or with some of the MANY APIs that have SDKs for VCPP - for example, DirectX. Quite a world. Let's start our journey.
I firmly believe that examples are the best way to learn tools like VCPP, *when assuming* previous knowledge, as I am assuming now. I don't believe in examples "falling from heaven", so if you don't know absolutely NOTHING about computer programming, I think it would be better for you to search another kind of tutorial, because a wrong start in Computer Science can really compromise your future! This is because of the way our brain works.
One of the most usual starting examples is the "Hello World" program, where you get the computer to print some message on the screen.
In standard C, that program can be as follows: hello.c source code (plain text file)
As you can see (please check the source code), I've made things a little more complicated, than I needed to. I did it, in order to call you attention to the following facts:
- remember that a C program must alway have a main function. You can have that function to have no return value and no parameters, but it is useful to understand how the program handles arguments. This first example, tries to show you how.
- arguments are kept in an array of string, indexed from 0. The element at [0] is the program executable, itself!
- stdout and stdin are FILEs, just like any other file. Watch how the program prints to stdout, usually the screen. If it was a regular FILE, you would have to fopen it...
- it is wise to control the return values of most function calls. Be sure to study when that return value indicates an error.
- this is a win32 console application. IT DOES NOT RUN in DOS mode (try it...). So, how you pass it arguments? The answer brings us to our first contact with PROJECT SETTINGS dialog box, accessible from PROJECT menu. Click on the DEBUG tab and fill the program arguments text field with whatever you want. The arguments will NOT be processed, as we have already seen from the program source code. Try calling the program with arguments "a1 a2 a3 a4" to obtain this output.
Here is the steps to build the application in VCPP 6:
#1 - Launch the Visual C++ application
#2 - Choose FILE / NEW
#3 - Choose a NEW Win32 Console Application with an EMPTY PROJECT. Then choose a folder location for it. In the picture, you can see that I chose L:\vcpp.prj\tutorials\. After that, think about a name for the application. The name you choose, will also be the name of a new folder, under the project location you entered. That folder will hold ALL the project's files and (may be) another two folders: one named DEBUG, which will correspond to your debug builds of the project, and the other named RELEASE, corresponding to your (must shorter files) final builds. You can create your own configurations, such as ALMOST_RELEASE, but I will not discuss that in this tutorial.
#4 - Click OK. You should get the following NEW PROJECT INFORMATION.
#5 - There you are. The project is up and running, only needing some file in :-) Pay attention to your workspace window: it has two tabs, one for the class view (that doesn't matter for this tutorial), and the other named file view, allowing you to check the files that are really on your project. This is important: it is not enough to copy a file to your project folder, to make it be in the project - you must add it from the FILE menu... read the next step.
#6 - You must now type your source file for the project. In this case, it is ONLY ONE source file, but it could be thousands of them! If you don't want to type the code, just copy the hello.c file to your project folder. Assuming that you are about to type the whole thing, you should select NEW / C C++ SOURCE FILE. Because C is NOT C++, and because this tutorial is about a C program under VCPP, be sure to choose a .C extension for the file, as the picture shows.
#6 - After adding the source code, you must build your project. Press F7 to do. Try to run the program, from the PROJECT / EXECUTE menu. You will probably see NOTHING happening, because the program is too simple and your PC too fast... but you can spice things up, by adding arguments to it, and then the VCPP environment will hold the output window, for you to check the results. In order to call the program with arguments, you CANNOT just go to DOS, change dir to the DEBUG folder, and execute it, because this is NOT a DOS binary.
#7 - To call the program with arguments, you must use the PROJECT / SETTINGS menu, and type whatever you want in the PROGRAM ARGUMENTS text field.
#8 - Run the program again. You should get an output like this one.
Very, very simple. This first lesson teached us the following:
- how to build empty applications, that can be written in plain C or C++, without requiring knowledge about the MFC.
- how to use the PROJECT SETTINGS dialog box to tweak something (the program arguments) from its default values.
- how to run the project, and understand that a win32 program is NOT DOS software.
- some C souvenirs :-)
We will be doing our first Windows thing...