Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows


Practical Learning: Creating a Top-Most Window



  1. To create the dialog box with a thin border, check its Static Edge check box or set it
    to True

  2. To indicate that this dialog can accept dragged files, check its Accept Files check
    box or set it to True


12.1.8..Creating the Dialog Resource File....................................................


As mentioned already, a dialog box means nothing except for the controls it is created to
host. The controls are listed in a section that starts with the BEGIN and ends with the
END keywords. Here is an example:

IDD_SCHOOL_SURVEY DIALOGEX 0, 0, 340, 268
STYLE WS_CAPTION | WS_SYSMENU | WS_POPUP | DS_MODALFRAME
EXSTYLE WS_EX_TOOLWINDOW
CAPTION “School Survey – For Teachers Only”
FONT 8, “MS Shell Dlg”, 400, 0, 0x1
BEGIN
END

If you design a dialog box and the first object of your application, you must save it before
using it. Even if you had decided to manually create the dialog box as a text file, you
must save it before using it. In both cases, whether saving the dialog box designed or the
text file, saving it results in creating a resource file. This file should have the .rc
extension.

If your resource file is using some identifiers, which is the case for most or all controls
you will use in your application, you must list them in a header file. This file is
traditionally called Resource.h or resource.h. Each identifier must be listed using the
following syntax:

#define Identifier Constant

When you save the resource file, Visual C++ automatically creates the resource header
file and names it resource.h

After saving the resource file, it is still considered external to the application. If you are
using MSVC 6, you must add it to your project. After it has been added to your project,
you can continue working on the dialog box, adding, deleting, or manipulating the
controls. After doing that, if you save the resource, Visual C++ automatically makes the
appropriate changes in the resource and the resource header files.

Practical Learning: Saving the Resource File



  1. If you are using MSVC 7, on the Standard toolbar, click the Save All button
    If you are using MSVC 6:
    a. To save the dialog box, click the system Close button of the window that holds
    the dialog box.
    b. This will display a window with a tree view that starts with Script1. Close its
    window also.

Free download pdf