Monday, 4 March 2013

Creating a Dialog-Based Application


Creating a Dialog-Based Application

A dialog-based application has no menus other than the system menu, and it cannot save
or open a file. This makes it good for simple utilities like the Windows Character Map.
The AppWizard process is a little different for a dialog-based application, primarily
because such applications can't have a document and therefore can't support database
access or compound documents. To create a dialog-based application, start AppWizard as
you did for the SDI or MDI application, but in Step 1 choose a dialog-based application,
. Call this application FirstDialog.

If you would like an About item on the system menu, select the About Box item. To have
AppWizard lay the framework for Help, select the Context-Sensitive Help option. The
third check box, 3D Controls, should be selected for most Windows 95 and Windows NT
applications. If you want your application to surrender control to other applications
through automation, as discussed in Chapter 16, select the Automation check box. If you
want your application to contain ActiveX controls, select the ActiveX Controls check
box. If you are planning to have this application work over the Internet with sockets,
check the Windows Sockets box. (Dialog-based apps can't use MAPI because they have no
document.) Click Next to move to the third step.
As with the SDI and MDI applications created earlier, you want comments in your code.
The decision between static linking and a shared DLL is also the same as for the SDI and
MDI applications. If your users are likely to already have the MFC DLLs (because they
are developers or because they have another product that uses the DLL) or if they
won't mind installing the DLLs as well as your executable, go with the shared DLL to
make a smaller executable file and a faster link. Otherwise, choose As A Statically
Linked Library. Click Next to move to the final step.
Step 3 of the AppWizard process for a dialog-based application deals with comments and
the MFC library.
Step 4 of the AppWizard process for a dialog-based application gives you a chance to
adjust filenames and classnames.
In this step you can change the names AppWizard chooses for files and classes. This is
rarely a good idea because it will confuse people who maintain your code if the
filenames can't be easily distinguished from the classnames, and vice versa. If you
realize after looking at this dialog that you made a poor choice of project name, use
Back to move all the way back to the New Project Workspace dialog, change the name,
click Create, and then use Next to return to this dialog. Click Finish to see the summary
of the files and classes to be created.
If any information on this dialog isn't what you wanted, click Cancel and then use Back
to move to the appropriate step and change your choices. When the information is right,
click OK and watch as the application is created.
To try it yourself, create an empty dialog-based application yourself, call it FirstDialog,
and accept the defaults for each step of AppWizard. When it's complete, choose Build,
Build to compile and link the application. Choose Build, Execute to see it in action.

Clicking the OK or Cancel button, or the X in the top-right corner, makes the dialog
disappear. Clicking the system menu in the top-left corner gives you a choice of Move,
Close, or About. Figure 1.21 shows the About box that was generated for you.


No comments:

Post a Comment