Share via


Adding Functionality with Code Wizards

Once you have created a project, you will want to change or add to that project's functionality. Such tasks include creating new classes, adding new member functions and variables, and adding Automation methods and properties. The code wizards are designed to let you do all these things.

Note

You can now add message handlers and map messages to them and override MFC virtual functions using the Properties window.

Accessing Visual C++ Code Wizards

There are three locations where you can access Visual C++ code wizards:

  • On the Project menu, the Add New Item command allows you to bring up the Add New Item dialog box, which helps you to add new files to your project. The Add Class command displays the Add Class dialog box, which in turn open wizards for each of the class types you can add to your project. The Add Resource command displays the Add Resource dialog box, from which you can create or select a resource to add to your project.

    If you highlight a class or an interface in your project in Class View, the Project menu also displays the following commands:

    • Implement Interface (from a control class only)

    • Add Function

    • Add Variable

    • Add Connection Point (ATL class only)

    • Add Method (from an interface only)

    • Add Property (from an interface only)

    • Add Event (from a control class only)

  • In Solution Explorer, right-clicking any folder and clicking Add from the shortcut menu allows you to add new or existing files, more folders, items, classes, resources, and Web references to the project.

  • From the Class View window, right-clicking the appropriate node and clicking Add from the shortcut menu allows you to add functions, variables, classes, properties, methods, events, interfaces, connection points, or other code to your project.

    Note

    Visual Studio does not provide a wizard to add an interface to a project. You can add an interface to an ATL project or to an Adding ATL Support to Your MFC Project by adding a simple object using the ATL Simple Object Wizard. Alternately, open the project's .idl file and create the interface by typing:

       interface IMyInterface {
       };
    
    

    See Implementing an Interface and Adding Objects and Controls to an ATL Project for more information.

    Access code wizard from

    Description

    Add New Item

    The Add New Item code wizards add source files to your project. If necessary, additional directories are created to contain the files where the project build engine expects to find them. Code wizards available from the Add Item icon include:

    • Add C++ source files (.cpp, .h, .idl, .rc, .srf, .def, .rgs).

    • Add Web development files (.html, .asp, .css, .xml).

    • Add utility and resource files (.bmp, .cur, .ico, .rct, .sql, .txt).

    These code wizards generally do not ask you for any information but add a file to your development tree. You may rename the file in the property window.

    Solution Explorer

    The code wizards available from Solution Explorer depend on where your cursor focus is when you right-click an item. If the Add option does not appear when you right-click an item, then move your cursor up one level in the development tree and try again. The code wizards will always place the additional code in the appropriate place in the development tree, no matter where your cursor is. Code wizards available from Solution Explorer include:

    • Add Class (opens the Add Class dialog box containing the new code wizards).

    • Add Resource (New, Import, or Custom).

    • Add Web Reference.

    Class View

    The code wizards available from Class View depend on where your cursor focus is when you right click an item. If the Add option does not appear when you right click an item, then move your cursor up one level in the class tree and try again. The code wizards will always place the additional code in the appropriate place in the development tree, no matter where your cursor is. Code wizards available from Class View include:

    The Add Class selection opens the Add Class dialog box, which gives you access to all the new Add Class code wizards.

See Also

Tasks

Overriding a Virtual Function (Visual C++)

Reference

Navigating the Class Structure (Visual C++)

Concepts

Visual C++ Project Types

File Types Created for Visual C++ Projects

Other Resources

Creating Desktop Projects By Using Application Wizards