- Table of Contents
- Copyright
- About the Authors
- About the Contributors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- How to Use This Book
- What You Need to Use This Book
- What's New in Visual C++ 6.0
- Contacting the Main Author
- Part I: Introduction
- Chapter 1. The Visual C++ 6.0 Environment
- Part II: MFC Programming
- Chapter 2. MFC Class Library Overview
- Chapter 3. MFC Message Handling Mechanism
- Chapter 4. The Document View Architecture
- Chapter 5. Creating and Using Dialog Boxes
- Chapter 6. Working with Device Contexts and GDI Objects
- Chapter 7. Creating and Using Property Sheets
- Chapter 8. Working with the File System
- Chapter 9. Using Serialization with File and Archive Objects
- Part III: Internet Programming with MFC
- Chapter 10. MFC and the Internet Server API (ISAPI)
- Chapter 11. The WinInet API
- Chapter 12. MFC HTML Support
- Part IV: Advanced Programming Topics
- Chapter 13. Using the Standard C++ Library
- Chapter 14. Error Detection and Exception Handling Techniques
- Chapter 15. Debugging and Profiling Strategies
- Chapter 16. Multithreading
- Chapter 17. Using Scripting and Other Tools to Automate the Visual C++ IDE
- Part V: Database Programming
- Chapter 18. Creating Custom AppWizards
- Chapter 19. Database Overview
- Chapter 20. ODBC Programming
- Chapter 21. MFC Database Classes
- Chapter 22. Using OLE DB
- Chapter 23. Programming with ADO
- Part VI: MFC Support for COM and ActiveX
- Chapter 24. Overview of COM and Active Technologies
- Chapter 25. Active Documents
- Chapter 26. Active Containers
- Chapter 27. Active Servers
- Chapter 28. ActiveX Controls
- Part VII: Using the Active Template Library
- Chapter 29. ATL Architecture
- Chapter 30. Creating COM Objects Using ATL
- Chapter 31. Creating ActiveX Controls Using ATL
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
Editing Resources
Developer Studio allows you to edit all of your resources with various visual editors that are part of Developer Studio. You can edit any resource by double-clicking it in the ResourceView. In the next few pages, you will be looking at the various resource editors provided by Developer Studio, starting with the Dialog box editor, which you will prob ably be using most often.
Dialog Boxes
In most applications, dialog boxes provide a large portion of the interface between the user and your application. Dialog boxes allow you to provide an interface to the user for certain sets of information as it is needed, without taking up real estate in your main window. Whenever you open a dialog box resource, you will get a window similar to the one shown in Figure 1.15.
Figure 1.15 Dialog Box editor.
Adding Controls
If you have just created a new dialog box, it's time to make it do something useful. Developer Studio makes this easy. You should notice the controls toolbar floating around your workspace somewhere when you open the dialog box. Each of the icons on the toolbar (with the exception of the pointer in the top left) represents a control that you can add to your dialog box, including any controls that you have added with Component Gallery.
To add a control, select it from the toolbar, click the dialog box, and you have a new control. If you are unsure of what some funny picture on the toolbar represents, just hold the mouse pointer over it. Like other toolbars, this will provide tooltip help that will give a short description of the control.
When adding a control, it is generally easier to assign its size and location when it is added by dragging a rectangle in your dialog box before releasing the mouse to insert the control. However, if you have already inserted a control, you can easily move it by clicking it and dragging a point within the control to the new location. You can easily resize controls by dragging the resize handles (little boxes) on the border of the selected control.
Control Properties
For most controls, you should change their properties after you have placed them in a dialog box. You can edit a control's properties by selecting Properties… from the context menu that you can pull up by right-clicking the control. The Properties dialog box looks similar to the one shown in Figure 1.16.
Figure 1.16 Control Properties dialog box.
The Properties dialog box will be a bit different for each type of control, but will always allow you to edit the resource ID. Although the ID can be a symbol or a number, you should try to give your resource ID symbol a meaningful name, rather than just a number or the default symbol name. If you want to force your ID to have a certain value, you can specify a value after the resource symbol like this:
IDC_MYBUTTON=123
For more information about the specifics of the styles and other options on the Properties page, press F1 to bring up context-sensitive help on the current page. You can access the properties of the dialog box itself by double-clicking a blank spot in the dialog box or its title bar.
Laying Out Your Controls
One of the trickiest parts of designing your dialog boxes can be getting everything to line up just right where you want it. The dialog box editor provides several nifty features for dealing with this in the Layout menu. Many of the options in the Layout menu will not be enabled unless you have a certain type of control selected or have several controls selected.
The Size to Content command in the Layout menu (or F7) is particularly useful with static text and button controls. This will make the control just the right size to contain its text, preventing characters from being clipped off or controls that run over your other controls.
You might notice a blue, shaded line encircling the contents of your dialog box. If you place any controls in the dialog box so that they touch this margin line, they will be automatically moved whenever you resize your dialog box. Unfortunately, this only works while you are creating your dialog box resource and will not help with resizing at runtime. You may create your own guidelines by dragging in either of the ruler bars at the top or left of your dialog box. By later adjusting these guides, any controls placed on the guide will be moved with it.
Tab Order
Windows allows you to move from control to control within a dialog box by use of the Tab key. This functionality is provided automatically when you create a dialog box in Developer Studio, but you might need to do a few things to tweak it to work just the way you want.
To adjust the tab order of your controls, you can choose the Tab Order command from the Layout menu and click the controls in the order that you want them to be tabbed. If you have a complicated dialog box and only want to change the tab order of a few controls, you can take a little shortcut by holding the Ctrl key down and selecting the last control that tabs properly before selecting the controls that tab incorrectly. Clicking an empty spot in the dialog box, or pressing Enter, will exit the tab order mode.
To prevent a control from being reached using the Tab key, clear the Tab stop checkbox on the control's property page.
Testing Your Dialog Box
You could save your dialog box and rebuild the application to test the layout of your dialog box, but there is a much simpler method of testing things like tab order. The Layout menu provides the Test command (you can also use Ctrl-T or that little switch on the Dialog Box toolbar) that will run your dialog box for you. This test mode ends whenever you exit the dialog box that you are testing.
Editing Menus
Double-clicking a menu resource in the ResourceView will open a window like the one shown in Figure 1.17 that allows you to edit your menu resource.
Figure 1.17 Menu editor.
To add a new menu item, double-click in the empty space to the right or bottom of the last menu item. This will open the Menu Item Properties dialog box, as shown in Figure 1.18, which lets you enter the menu caption, its associated command ID, and style information. You may freely rearrange your menu items by dragging and dropping.
Figure 1.18 Menu Item Proper ties dialog box.
The Command ID that you enter here will be the command ID that your application will receive when the user selects this menu item.
The Caption is the text that is displayed for the menu item. Placing an ampersand (&) in front of a character will cause that character to become the mnemonic key for that menu item. It is also customary to include text information about accelerators after the caption text, separated by a tab sequence (\t).
The Prompt field is used to enter text that will appear on the status bar when the cursor is on this menu item.
If you choose the Separator style, this will not be a real menu item, but just a separator between menu items. The Checked, Grayed, and Inactive styles determine the initial state of the menu item; these may be changed at runtime. The Help style will cause the menu item to be displayed on the far right of the menu bar, but this convention isn't used as often now as it once was.
By choosing the Pop-up style, you can easily create layers of menus. If you are creating a menu that will be used as a pop-up, you can select the View as Popup option from the right-button context menu to tell the menu editor to display your menu as a pop-up while you are editing it.
Other Resources
Developer Studio also provides visual editors for the other common windows resources, including accelerator tables, bitmaps, icons, cursors, string tables, and toolbars. You may also edit version resources to track various information about the version of your application.
In addition, you may define your own custom resource types that will be bound with your application. Because Developer Studio doesn't "know" how you intend to use these resources, you can only edit these resources in a binary format. You can, however, import existing files into your custom resource.
MFC AppWizard | Next Section

Account Sign In
View your cart