Wap2kVisualTut

download Wap2kVisualTut

of 19

Transcript of Wap2kVisualTut

  • 8/7/2019 Wap2kVisualTut

    1/19

    If you are a beginner on Microsoft Visual Studio 2008 then you will at first find that thispowerful program is not that easy to use for a beginner this is the aim of this tutorial. I

    hope that it helps quite a few people out.

    I am assuming that you are not a complete n00b and have installed Microsoft Visual

    Studio. I have install the complete set of tools that Microsoft have available where as you

    might have just Install Microsoft Visual C++ (cpp) OR C Sharp (c#) or any tools thathelp with the programming language that you are aiming to use to program you

    applications so parts of this tutorial may not be very useful to you.

    There may be slight differences in the way that youre Microsoft Visual Studio looks

    compared to the ones in the screenshots and some of the features may be missing as I amusing Microsoft Visual Studio Professional and I am also running Microsoft Windows

    Vista Ultimate Edition at the time of writing this tutorial.

    In this tutorial I will be using Microsoft Visual Studio to create a win32 application so

    if you are not using c++ these tutorials may become useless to you all together.

    Opening Microsoft Visual Studio

    On Microsoft Windows Vista and XP to open the visual studio do the following:

    Start Menu => All Programs => Microsoft Visual Studio 2008 => Microsoft VisualStudio 2008.

    Thats all there is to it you have now successfully opened Microsoft Visual Studio and

    you should now see the Microsoft Visual Studio splash screen (see Figure 1.0)

    Figure 1.0

  • 8/7/2019 Wap2kVisualTut

    2/19

    Lets Explore the Studio

    Ok so now lets have a look at the Microsoft Studio Layout the first page that you willsee is the start page (see Figure 1.1) this will be the very first page that you will see every

    time you open Microsoft Visual Studio and also when you close all any open solutionsthat you may have open. This will be the case unless you have set one of your Projects tobe your Default Project when opening Microsoft Visual Studio in that case the Default

    Project will open up automatically and the start screen will be totally bypassed until you

    close the open Solution.

    Figure 1.1

  • 8/7/2019 Wap2kVisualTut

    3/19

    The Recent Projects (Figure 1.3) is the area of the start screen is where all the projects

    that you have been working on will appear in a ordered list the last project that you

    worked on last appears at the top of the list.

    To carry on working on a project simply click on the project name in the Recent Projects

    list and it will open the Project that you clicked for you.

    I find to be a very useful feature. The Recent Projects also includes options to create a

    new project and open any other project that isnt displayed on the list simply click the

    project links next to Open: and Create: Text Labels

  • 8/7/2019 Wap2kVisualTut

    4/19

    Figure 1.3

    The main area (Figure 1.4) of the start screen includes a list of articles from the MSDN

    (Microsoft Developer Network) website which is a very useful place to go when you

    need help and has references for all the programming languages that come with visualstudio. Simply click on any of the links in this area and if you are connected to the

    internet you will be taken to the MSDN website article that you chose.

    Figure 1.4

  • 8/7/2019 Wap2kVisualTut

    5/19

    The Getting Started screen (Figure 1.5) is a list of links that will help you get startedusing visual studio and you may find that the links in this area are very useful simply

    click on the titles to go to the news article or help document.

    Figure 1.5

  • 8/7/2019 Wap2kVisualTut

    6/19

    The getting Visual Studio Headlines screen (Figure 1.6) is a list of links that will havenews about the visual studio I.D.E updates and other interesting headlines that Microsoft

    Microsoft thinks may be of interest to the users of visual studio

    Figure 1.6

    Creating a Project

    The first thing to do is to create a new project for our program. To create a project, followthese 6 easy to follow steps:

    1. Under the File menu, Select New, and then select Project from the Sub Menu that

    appears (Figure 1.7). Alternatively, you can press Ctrl+Shift+N (Shortcut KeyCombination). The New Project dialog box will be displayed (Figure 1.8).

    Figure 1.7

  • 8/7/2019 Wap2kVisualTut

    7/19

    Figure 1.7

    2. Enter a name for your Project in the Name box the Solution name will mirror the

    Project name so there is no need to fill it in or change it but ill leave that step up

    to you.

    3. Select which type of Project you will be creating in the Project Types Pane on the

    left, and then select a template from the Templates pane on the right.

    4. Choose a location for your new project in the Location box, either by typing a

    directory path or by clicking Browse and navigating to the appropriate directory.

    5. Click the OK button and the Win32 Application Wizard will be displayed (Figure

    1.8). This Project will possess a simple, Win32 interface, and will display a

    message box onto the screen for our test purpose. Before proceeding, though, youneed to change some setting Click next on the Win32 Wizard Setting wizard will

    appear (Figure 1.9).

    Figure 1.8

  • 8/7/2019 Wap2kVisualTut

    8/19

    Figure 1.9

  • 8/7/2019 Wap2kVisualTut

    9/19

    6. Know comes the point where you decide what type of support you application

    will need ill explain a little about each option below

    Under Application Type:

    Windows Application

    Check this option if the application you are programming is for windows WIN32 API

    Console App

    Check this option if your application is going to be aimed at the windows console

    (Looks similar to dos console)

    Dll

    Select this box if you are creating a DLL (Dynamic Link Library) File Dll,s are files thatyou can include in your application to make it easy to manage parts of your code if you

  • 8/7/2019 Wap2kVisualTut

    10/19

    have a large project and dont want to have to recompile youre whole application to be

    able to update a tiny part of your code. Dll,s end in the .dll extension

    Static Library

    Select this option if option if you want to create a static library which is similar to a dllbut if you use one of these the size of your application will become huge compared to

    application that use Dll,s because the code from the librarys are put inside of your

    application when you compile it.

    Under Add Common header File For:

    ATL

    Check this option if you are planning to user the ATL (Active Template Library) librarys

    in your applicants so that the program you create will include the header files for the

    Librarys. MFC was introduced in 1992 with Microsoft's C/C++ 7.0 compiler for usewith 16-bit versions of Windows as an extremely thin OOP/C++ wrapper for Windows

    API (C). C++ was just beginning to replace C for development of commercial applicationsoftware (as predominant way to interface the API). With that, they also shipped the very

    first replacement for (older, alphanumeric) IDE called PWB. New "App Studio" was a

    good set of designers available at the time, still existent today (2008).

    MFC

    Check this option if you are planning to user the MFC (Microsoft Foundation Classes)librarys in your applicants so that the program you create will include the header files for

    the Librarys. The Active Template Library (ATL) is a set of template-based C++ classes

    developed by Microsoft that simplify the programming of Component Object Model(COM) objects. The COM support in Visual C++ allows developers to create a variety of

    COM objects, OLE Automation servers, and ActiveX controls.[1] [2] Patterned after the

    Standard Template Library (STL), ATL includes an object wizard that sets up primarystructure of the objects very quickly with a minimum of hand coding. The current most

    up to date version of the Microsoft Microsoft Foundation Classes is 9.0

    Under additional options:

    Empty project

    Check this box if you want your project to be empty and not use the default template

    includes and code template that is included

    Export Symbols

    This option will only become available if the empty project is checked. You only have to

    use this option if you wish the compiler to export symbols from dlls when linking to them

  • 8/7/2019 Wap2kVisualTut

    11/19

    in your application at the compiler

    Precompiled Header

    This option if you with to use a PrecompiledHeader to help out the compiler.

    In many programs, the majority of header files that are included are provided by theoperating system. As a result, the compiler spends a significant proportion of its time

    parsing the same files for every program that is compiled on a given platform. In modern

    operating systems, there can be literally thousands of header files, and in some casesmany or all of these are included by a single master include file such as windows.h on

    Windows or Cocoa/Cocoa.h on Mac OS X.

    In order to reduce compilation times, modern compilers often allow these header files,

    which rarely change, to be pre-compiled into a form that is easier for the compiler toload. This intermediate form is known as a pre-compiled header, and is commonly held

    on disk with the extensions .pch or .gch.

    7. Thats it simply click the Finish button to create the project. The wizard correctlyinitializes all the compiler settings for the project.

    If you got this far well done you now know how to open Visual Studio What the start

    Screen does and how to create a new project.

    Using the Solution Explorer

    Adding a Files to your Project

    1. Right Click the folder you want to add a file to in the solution explorer and select

    Add then New item (Figure 2.0) or click the add new item button on the toolbar(see Figure 1.10) in my example I want to add a header (.h) file to my project but

    you may add anything you want to your project after clicking new item.

    2. Select the type of file you want to add from the box that opens (Figure 2.1) there

    all labeled and it should not be that hard to figure out what each file is used for if

    you have a little programming experience of enter there names into Google or

    Wikipedia and do a little research after selecting the type of file you want to addenter a file name in the Name box.

    3. Choose a location for your new project in the Location box, either by typing adirectory path or by clicking Browse and navigating to the appropriate directory.

    The default location should be ok though. To finish click Ok.

    Figure 1.10

  • 8/7/2019 Wap2kVisualTut

    12/19

    Figure 2.0

    Figure 2.1

  • 8/7/2019 Wap2kVisualTut

    13/19

  • 8/7/2019 Wap2kVisualTut

    14/19

    2. Now edit and add the code for your program in code window (Figure 2.3)

    Figure 2.3

    Compiling and Executing the Program

    Building the Executable

    The next thing to do is build the source into a executable file. The term build in Visual

    Studio I.D.E refers to compiling and linking the program. Visual Studio .NET compiles

  • 8/7/2019 Wap2kVisualTut

    15/19

    any source files that have changed since the last build and any new resources into object

    files (.obj), if no compile errors were generated in the compiler, then the build process

    will carry on to the linker to perform a link of the generated object (.obj) files into aexecutable file.

    To build the executable, select Build Solution from the Build (Figure2.5) menu or pressCtrl+Shift+B or F7.

    Figure 2.5

    An Output window displaying the build progress will appear near the bottom of the

    Visual Studio .NET window. If no errors are encountered, the message Build: 1

    succeeded, 0 failed, 0 skipped should appear in the Output window (Figure 2.4).

    If any problems occur, the Output window will contain a list of errors and warnings, asshown in figure 2.4.

    Figure 2.4

  • 8/7/2019 Wap2kVisualTut

    16/19

    Executing your program

    Once youve eliminated all errors and youve successfully built the project, you can

    finally execute the program. Choose Start without Debugging from the Debug menu to

    run the program. You can also press CTRL+F5 to execute the program or the easiest wayis to use the Start Debugging button on the toolbar (Figure 2.6).

    Figure 2.6

    Linking Library Files

    There are two ways I know of to link library files to your project the first way can be

    used in your source (.cpp file) at the top or in a header file (.h file) type the following bitof code:

    #pragma comment(lib, "libname")

    Where libanme is the name of the library

    The second way in which you can link lib files is to go to the project menu then

    Properties (see Figure 1.7) in the properties select

    Configuration properties => Linker => Input

    Then add the names of your lib files in the Additional Dependencies box like:

    Libname1; libname2; Libane3 (See Figure 2.8)

    Figure 2.7

  • 8/7/2019 Wap2kVisualTut

    17/19

    Figure 2.8

    Checking for I.D.E updates

    Click Help => Check for Updates (See Figure 2.9)

    Removing Files

  • 8/7/2019 Wap2kVisualTut

    18/19

    Right click on the file you want to remove in the solution explorer and click the delete

    option or press delete key. (see Figure 2.10)

    Renaming Files

    Right click on the file you want to rename in the solution explorer and click the renameoption or press F2. and retype the name of the file (see Figure 2.10)

    Figure 2.10

    Including

    In your code you can create header files into cpp files the header files that you create can

    be included in your cpp files like this:

    #include "stdafx.h"

    And common windows header files like this

    #include

    Important note:

    stdafx.h is required by Visual C++ Win32 API apps if you dont have

    #include "stdafx.h" as your first header then it will not compile

    Figure 2.9

  • 8/7/2019 Wap2kVisualTut

    19/19

    Tutorial Credits

    Author

    Wap2k [email protected]