VCPP 6 - TUTORIAL - LESSON #2 DHTML (c) Artur Marques, 07 August 1999

previous lesson [Lesson #1]

The VCPP6 development environment

Genuine Windows application #1 [in 11 steps]

Download the final executable version you should get, by the end of this lesson

next lesson [Lesson #3]


The VCPP6 development environment

When you start the VCPP6 application, you get what it is called the "development environment", where you can find toolbars, panes, and the editor area. The pictures here shown are from an empty project.

workspace pane ; output pane ; editor area ; standard toolbar ; WizardBar ; Build MiniBar


The workspace pane will deserve much of your attention, while you are creating your VCPP 6 programs. From the workspace pane you can access the "class view", the "resource view" and the "file view".

class view allows you to take an organized, hierarchical view, at the classes of your C++ project. If you are doing a plain C progam, not using the class data type, this view will still be very interesting, showing your functions, variables, constants and their scope.

resource view shows you the "resources" your project is using, and that means your dialog windows, icons, menus, bitmaps, cursors and so on.

file view is of great importance to big projects, holding information of all your files: source files, header files and resource files. Any file on your project's folder that is NOT listed by this view is not being considered, while building the project. From this view it is also very easy to navigate / edit from file to file.


The output pane will show you all the messages that VCPP6 wants you to know about. It will display warnings and erros, resulting from the compilation / build processes; it will also be used by the debugger to show the values of the identifiers you choose to watch. This pane is also organized in several views, that you can switch to... some of these views, offer you the power to search files for identifiers, review build errors, etc...

The editor area is where your eyes will "rest" :) most of the time. You will edit your files, from windows that will be on this area. This is also where you will design your application's windows, using the "window / icon painter". I call "editor area" to everything on the VCPP6 environment, that is not panes, menus or toolbars.


When you first start VCPP6, there are some toolbars available; you can customize their buttons and locations, or you can create your own toolbars. The "default" toolbars are the "Standard Toolbar", the "WizardBar", and the "Build MiniBar".

The Standard Toolbar has the buttons for most file and clipboard functions: open, save, save as, copy, cut, paste, and so on...

The WizardBar is very related to the powerful Class Wizard, a VCPP 6 tool that makes it easier to relate design resources to code. Class Wizard deserves much attention, but for now I'll stick only to the "it exists" knowledge.

The Build MiniBar is kind of a shortcut to the build and run commands. Somehow, I've never get used to it, and I prefer to use the correspondent menu.


Genuine Windows application #1

On the first lesson of our VCPP6 tutorial, we built a full console application in standard C. This means that that application will run on any computer where you can compile ANSI C. That is a good thing, but we must go farther and build software native to the Windows OS, which is the purpose of the VCPP6 environment...

So, now that you've familiarized yourself with the basics of the VCPP6 interface, we will build our first genuine Windows application.

Follow these steps, from VCPP6:


#1 - choose FILE / NEW and then MFC AppWizard (exe) - check the picture here.


#2 - choose a folder where to store the project's files and a project name. For example, if you want to call this project "002_winapp1" [as I did call him], enter that string as the project's name; and if you want the whole stuff to be in a folder "\vccp.prj", go ahead and type that as the folder. The VCPP6 environment will auto-create folders when needed - check the picture here.
#3 - Click the next button. Now you will have to choose what kind of MFC [Microsoft Foundation Classes] project you want to create. Options are "single document", "multiple document" and "dialog based". Choose "dialog based" - check the picture here.
#4 - Click the next button and face the next dialog box; there you have to choose some features your application will / will NOT use... for the sake of our first simple example, uncheck the "ActiveX Controls" and keep everything else as it is. For short, we will be creating an application with just an "About" dialog box, with 3D buttons. "3D buttons" is just a fancy name for the buttons you are used to: the ones that go down on depth, when clicked :) - check the picture here.

By default the title of the application's window you are creating, will be the name of the project - "002_winapp1"... if you want some other name, such as "my first winapp", go ahead and type it.


#5 - Click the next button and handle the pre-final dialog box! Just leave everything at their defaults. This last dialog box allows you to choose if VCPP6 will generate comments for the code in the files, and some another "tech" option, related to DLLs, which are something we will learn about later - check the picture here.
#6 - Click the next button and see the names that VCPP6 will give to the classes it needs. There will be two classes: one for the "About" dialog box, and another for the application itself - check the picture here. You can change the name of the application's class, but don't do it. Notice how VCPP6 follows the convention of starting the identifier of classes, with a uppercase "C". Click the finish button.
#7 - What follows is a review of your project options. Read the dialog box and click OK.

Notice how the development environment animates; the workspace pane gets a life and should show you the resources of the project or some of its other panes. The editor area should display a graphical editor of your application's window. The "TODO" label means "to do". Build the application.You should get no errors. Run [!] the application.

Now, learn how to modify the design of the application. From the workspace pane choose the resource view and double-click [activate] the resource that corresponds to the application's main window. Every resource has a name. Every dialog box is suggested to have a name, starting with IDD [IDentifier Dialog]. The name of the application's main window depends on the name of the project. If you have followed this tutorial's name, you will be looking for resource named IDD_MY002_WINAPP1_DIALOG.


#8 - Rearrange the look / design of the window, until you are happy with it. I did my changes by accessing the properties of the controls on the window. Do that yourself by secondary-clicking on the objects, such as the buttons. Try to change the button's names. You can also change the button's internal IDs, but don't do that now. Delete the "TODO" label; to do that, just press "delete" on your keyboard, after clicking on that text control.

Call the "OK" button something like "HELLO!" and call the "CANCEL" button "CLOSE".

Recompile and re-run the application. Watch how everything works how it did before, just with a different look.


#9 - Change the ID of the "HELLO!" button. Recompile and re-run the app. Notice how the HELLO button does NOTHING. Why?- Because MFC applications have macros in the auto-generated source code that associate some IDs to some events and functions to happen when the events [such as a left button click] occur. When you changed the ID of the once called IDOK button, you changed the ability of that button to close its parent window, which was the application's main window!

Lets fix that and add new code to our app. We want the app to show a message, when the HELLO button is activated [left-clicked, by default].


#10 - By secondary-clicking on the HELLO! button, change its ID to IDHELLO; then choose ClassWizard [CW]. The CW allows you to associate messages to objects; this means that when the OS receives the message, it sends it to the selected object. Then you must add a "member function" to the object that will handle the message. Check the picture here.

You are supposed to add a OnHello member function, to the IDHELLO object, that handles the BN_CLICKED message. In plain english, you want the button to display a message, when being clicked. Lets do that... Choose "edit code".


#11 - The code you are to edit, will first look like this:

void CMy002_winapp1Dlg::OnHello (){

};

This is the signature of the method OnHello, of the class CMy002_winapp1Dlg. This method returns nothing (void) and has no parameters. For now it is also empty on code... Add the code:

MessageBox ("We're done. Lesson #2 ends!");

Remember that C and C++ are case-sensitive!

Recompile and re-run the application. Have fun with editing the icon and adding minimize / maximize buttons to the main window, by editing the properties of that window.

If you want the message box to display a caption different from the application's name, just use a 2nd parameter; for example:

MessageBox ("We're done. Lesson #2 ends!", "Message");


download my final win32 executable. Reach the same application. [65 K zip file]