Chapter 29

Power-User Features in Developer Studio


CONTENTS

Developer Studio is a terrifically complex application, enabling you to manage your programming products in almost any way imaginable. Some features of Developer Studio are easy to use, once you know what they do. Others require sophisticated knowledge of programming and of the various tools that Developer Studio puts at your disposal. In this chapter, you get an introduction to some of the more useful advanced features of Developer Studio, with which you may not yet have had experience.

Using Component Gallery

In these days of complex programs, reusability has become more than just a buzzword. It's become a survival technique for programmers who find themselves with the awesome task of creating hundreds of thousands of lines of working source code in a minimum amount of time. Component Gallery (Figure 29.1) is one way that Developer Studio helps support the concept of reusability. Component Gallery gives you instant access to everything from reusable classes and OLE controls to wizards. You can even create your own components and add them to Component Gallery. In fact, in its default installation, Developer Studio automatically adds a category to Component Gallery for new AppWizard applications that you create.

Figure 29.1 : Component Gallery organizes reusable components, including classes and OLE controls.

Suppose you have a dialog box that you use frequently in projects. You can create this dialog box just once, add it to Component Gallery, and then merge it into new projects whenever you need it. To see how this might work, follow these steps:

  1. Start a new AppWizard project workspace called MyApp. (Just use all the default AppWizard settings.)
  2. Create the dialog-box resource shown in Figure 29.2, giving the dialog box the IDD_NAMEDLG resource ID.
    Figure 29.2 : This is the dialog box you'll add to Component Gallery.

  3. Use ClassWizard to associate the dialog-box object with a class called CNameDlg. Make sure that the Add to Component Gallery option in the Create New Class dialog box is checked, as shown in Figure 29.3. Developer Studio then adds the component to Component Gallery.
    Figure 29.3 : Use ClassWizard to create a class for the dialog box.

  4. Start another AppWizard project workspace, this time called MyApp2.
  5. Select the Insert, Component command from Developer Studio's menu bar. Component Gallery appears.
  6. Select the MyApp tab. The components in the MyApp project appear (Figure 29.4).
    Figure 29.4 : You'll find the new dialog-box component on the MyApp page.

  7. Select the NameDlg component and then click the Insert button. Developer Studio asks whether you want to insert the component. Click the Yes button. Click the Close button to exit from Component Gallery.
  8. Check the MyApp2 project's classes, and you'll see that Component Gallery has added the CNameDlg dialog box (Figure 29.5). You'll also find the class's .cpp and .h files added to the project's file list.
    Figure 29.5 : The dialog-box component has now been added to the project.

You can use Component Gallery to manage many other types of components, including those that you might get from a friend or buy from a third-party supplier. Component Gallery can add, delete, import, and edit components in a variety of ways, depending upon the type of component with which you're working. Take some time to experiment with Component Gallery, and you'll quickly see how easy it is to use. (Your Visual C++ online documentation contains more information on Component Gallery.)

Introducing Custom AppWizards

AppWizard is a sensational tool for getting projects started quickly and easily. However, because of its general nature, AppWizard makes many assumptions about the way you want a new project created. Sometimes, you may need a special type of AppWizard project that isn't supported by the default AppWizard. If this special project is a one-time deal, you'd probably just go ahead and create the project by hand. However, if you need to use this custom project type again and again, you might want to consider creating a custom AppWizard.

You can create a custom AppWizard in three ways: using the existing AppWizard steps as a starting point, using an existing project as a starting point, or starting completely from scratch. However, no matter what method you choose, creating a custom AppWizard can be a complicated task, requiring that you understand and be able to write script files using the macros and commands provided by Visual C++ for this purpose. The creation of these script files is beyond the scope of this book. However, the following procedures will give you a general idea of how to create a custom AppWizard.

  1. Start a new AppWizard project workspace, choosing Custom AppWizard as the project type (Figure 29.6).
    Figure 29.6 : First, start a custom AppWizard project workspace.

  2. Click the Create button. The Step 1 of 2 dialog box appears.
  3. Choose the type of custom AppWizard that you want to create. In this case, select Standard AppWizard Steps, and name the project type MyWizard, as shown in Figure 29.7.
    Figure 29.7 : You use this dialog box to choose the type of AppWizard you want to create.

  4. Set the number of custom steps (near the bottom of the dialog box) to 6.
  5. Click the Next button. The Step 2 of 2 dialog box appears.
  6. Choose whether you want the AppWizard to create an executable file or a DLL. Also, select the languages that the AppWizard will support (Figure 29.8).
    Figure 29.8 : In this dialog box, you select the program type, as well as choose language support.

  7. Click the Finish button. Your custom AppWizard's settings appear. Click the OK button to generate the project workspace.

After you've completed the preceding steps, your custom AppWizard project is ready for you to add the custom code needed to create the wizard. As you can see in Figure 29.9, the new project looks a lot like any other project you might create with Developer Studio, except that it contains some file types with which you may not yet be familiar.

Figure 29.9 : A custom AppWizard project workspace is much like other workspaces you've used.

The classes that end with "Dlg" are the classes that represent the dialog boxes that'll appear for each step of the wizard. You need to use the resource editor to customize the dialog-box objects that are associated with each of the classes. As mentioned previously, there are also script files-CONFIRM.INF and NEWPROJ.INF-that you must customize to create the wizard's steps.

When you compile the custom AppWizard, Developer Studio creates the final files and stores them in your Msdev\Template directory. The next time you choose to start a new project workspace, your custom AppWizard will be listed in the project types (Figure 29.10). To remove the custom AppWizard, delete the wizard's .awx and .pdb files from your Msdev\Template directory.

Figure 29.10 : After you compile your custom AppWizard, it'll appear as a project type in the New Project Workspace dialog box.

Integrating External Tools

When you first install Visual C++, it supplies a set of default tools that you can use to help manage and create your programs. These tools include Spy++, MFC Tracer, OLE Control Test Container, and others. Although these tools are handy, you'll undoubtedly run into other tools that you might like to add to your Visual C++ programming environment. Suppose, for example, that you want to install WordPad as an editor on your Tool menu. You'd just follow the procedure given here:

  1. Select the Tools, Customize command from Developer Studio's menu bar. The Customize property sheet appears (Figure 29.11). Click on the Tools tab.
    Figure 29.11 : You add tools from the Customize property sheet.

  2. Click the Add button. The Add Tool dialog box appears.
  3. Use the Browse button to locate the new tool on your hard drive. In this case, the new tool is WRITE.EXE, as shown in Figure 29.12. When you've located the tool, click OK.
    Figure 29.12 : Use the Browse button to locate the new tool.

  4. Type WordPad in the Menu Text box. This is the name of the tool as it will appear in the Tool menu.
  5. In the Arguments box, type the arguments that you want sent to the tool when the tool is run (Figure 29.13). In this case, type $(FileName)$(FileExt), which will cause the full name of the currently open source-code file to be sent as an argument to the tool. (You can select these arguments from a drop-down list if you click on the arrow button to the right of the text box.)
    Figure 29.13 : You can have arguments passed to the tools by typing the arguments in the Arguments text box.

  6. Click the Close button to finalize your selections. Developer Studio adds the new tool to the Tool menu (Figure 29.14), from which you can run the tool easily.
    Figure 29.14 : The newly added tool appears on the Tool menu.

You can purchase many additional tools from software vendors, not the least of which includes Microsoft's Visual SourceSafe-a project version-control manager-and VisualTest-a program-test automator. Other tools you might like to add include sophisticated source-code editors and debugging utilities.

Using Editor Emulation

The type of text editor you like is often a product of your experience. That is, once you've learned one way of doing things, you tend to be resistant to change. Previously, you learned that you can add your text editor of choice to Developer Studio's Tools menu. In addition, Developer Studio's built-in editor is capable of emulating two text editors: BRIEF and Epsilon. The text editor can also act like the text editor that came with Visual C++ 2.0. If you want to use the built-in editor, you should experiment with these various emulations to find the one that best suits your working habits. To set editor options, including emulation, follow these steps:

  1. Select the Tools, Options command from Developer Studio's menu bar. The Options property sheet appears.
  2. On the Editor page (Figure 29.15), set the Window Settings and Save Options for the text editor.
    Figure 29.15 : You use the Editor page to control general text-editor settings.

  3. On the Tabs page (Figure 29.16), set the way you want the text editor to handle tabbing.
    Figure 29.16 : You can also set how the text editor deals with tabs.

  4. On the Compatibility page (Figure 29.17), set the editor type in the Recommended Options For text box.
    Figure 29.17 : You set the actual emulation on the Compatibility page.

  5. Set the options in the Options box by checking those features that you want active.
  6. On the Format page (Figure 29.18), set the formatting features that you want used in your text windows, including fonts and text colors.
    Figure 29.18 : The Format page enables you to set the appearance of text windows.

Using Optimization

As most programmers know, the size and speed of a program are inversely proportional. That is, making a program faster often also makes it larger. Conversely, making a program smaller often also makes it run slower. Just as you're presented with these types of choices as you're creating the source code for your application, so too is the compiler forced to decide between different ways of producing executable code. By setting different optimization options, you can tell the compiler whether you want fast or slow code.

To find the optimization options, select the Build, Settings command from Developer Studio's menu bar. (You must have a project open in order to enable the Settings command. The settings are specific to the current project.) When you do, the Project Settings property sheet appears. Go to the C/C++ page and select Optimizations in the Category box. As you can see by examining the Optimizations box, Developer Studio defaults to no optimization. To select a type of optimization, just choose from the drop-down list, as shown in Figure 29.19.
Figure 29.19 : Select from the list the type of optimization that you want.

NOTE
If you select the Customize option in the Optimizations box, you can select from the list of individual optimizations, including Assume No Aliasing, Global Optimizations, Favor Fast Code, Generate Intrinsic Functions, Frame-Pointer Omission, and more. However, as you can tell from the names of these optimizations, you really have to know what you're doing to set up a custom optimization scheme.

From Here...

This chapter only touched upon the many advanced features you can discover in Developer Studio. Your Visual C++ online documentation contains a wealth of information about the features covered in this chapter and about many other features not mentioned here. The more you become familiar with Developer Studio's many advanced features, the better you'll understand the program-creation process.

For more information on related topics, please refer to the following chapters: