Download - 3 Visual C++ 6.0 IDE Tools
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
1/16
Chapter 3
Visual C++ 6.0 IDE Tools
Objectives
Building and customizing a typical MFC application using code generators
Describe the tools in the Integrated Development Environment Studio that
can be used to develop MFC applications.
Create and implement common control bars like Tool bars
Status bar
Dialog bars.
IntroductionOne of the great strength of the visual C++ development system is its capability to create highly
functional application skeleton through the AppWizard tools. AppWizard can be used to generate
skeleton MFC applications with verity of OLE, database, windowing, help and other options.
AppWizard can also be used to create windows DLLs; in addition, specialized exists for creating
ActiveX controls and custom AppWizard.
This chapter explains in details how to create a windows project and the different type of
application that can be created with the help of AppWizard. Process of creating a dialog based
application is much shorter than creating a document-based application. ClassWizard is used to
add message-handlers with the help of message map page and add member variable with the
help of member variable page.
This chapter describes how to create and implement control bars like toolbars, status bars, anddialog bars. In general, status bars provide the user with information about the status of the
application, such as position of the cursor or the current time. A dialog bar is a control bar with the
tool bar characteristics and dialog-box characteristics.
Creating Windows Projects
Types of Windows application created through AppWizard.
ClassWizard
When you select the New command from Visual Studios File menu, you are presented with the
new dialog. When the file tab is selected in this dialog, you are presented with the choice of
creating a new file that can be a text file, a source or header file, bitmap, or any of variety of other
file types
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
2/16
Page 32 Visual C++ 6.0 IDE Tools
However, if you select the project tab (and the default if you currently have no workspaces open),
you are presented instead with a variety of project types as shown in figure below.
Several of the choices presented here can be used to create skeleton applications for windows
executable programs and for windows DLLs. The following sections examine these options in
detail, starting with the most prevalent of AppWizard, the MFC executable AppWizard .
Note :AppWizard will create your project in the default location in the directory. C:\Program
files\MicroSoft Visual Studio\My Project. If you want you can enter a different location in
the Location Edit box.
Types of Windows Applications Created throughAppWizard
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
3/16
Visual C++ 6.0 IDE Tools Page 33
Document based MFC Application
Dialog based MFC Application
If you select MFC AppWizard (.exe) as the type of your new project, you are presented with
step one of a multi step Wizard process as shown in figure below. In this first step you can
decide characteristic of your new applications: whether it will have a single-document-based,
multiple-document-based, or dialog-based user interface.
A single-document-based application can present only one file to the user at any given time.
A good example for such an application is the windows NotePad.
A multiple-document-based application, in contrast, can present several documents, at once,
each in its own child window. Many word processing application such as Microsofts Word for
windows are multiple document-based applications.
A Dialog-based application presents a single dialog as its user interface. These applications
are used when all user interactions can take place through a single dialog template. An
example for a dialog-based application is the windows Character Map.
During this first AppWizard step, you can also specify the language of your application.
Your language selection defines which standard MFC resource set will be included with yourproject.
You can also use the AppWizard to create a project that supports multiple languages. To do
so, create the additional resource files (perhaps by rerunning AppWizard to create dummy
project in the desired language) and add the new resource files to your project. Create
additional project configurations, including and excluding resource file as needed.
Document based MFC Applications
The creation of single or multiple-document-based (SDI or MDI) applications through
AppWizard is nearly identical procedures, consisting of the same AppWizard steps.
The project files created by AppWizard for SDI and MDI projects are some what different,in particular, for an MDI project, AppWizard generates an additional class, CChildFrame,
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
4/16
Page 34 Visual C++ 6.0 IDE Tools
that represents MDI child windows.
After you select one of these document-based options, clicking the next button takes you
to step 2 of a six-step process. In this step figure as shown below you must specify the
level of database support your application will provide. Database support in the form of
MFCs open database connectivity (ODBC) and Data Access Objects (DAO) classes.
The meaning of the None option is obvious. The header files only option creates a project
with the necessary header files included, but otherwise the projects files will be no
different from files in a project with no database support.
The remaining two options represent significant additions to your projects view class will
be a class derived from CRecordViewofCDaoRecordView; second, a new class, derived
from CRecordSetorCDaoRecordSet, will be added to your project. The new view class is
dialog template-based and represents the fields in a record; the record set class provides
an internal representation for those fields and methods to access the underlying tables.
The difference between the Database view with file support and Database view without
file support options in AppWizard step 2 is simple. The former provides menu and toolbar
commands to load and save files; the latter does not. Often, when creating a databaseapplication, your applications document class provides merely a transient representation
of the database and does not need to be saved; in this case, use the Database view
without file support option.
Regardless of which of these two options you choose, before you proceed to AppWizard
step 3, you must also specify a data source. The data source is a table or set of tables in
a database that can be accessed through the ODBC or DAO mechanism. To select a
data source, click on the Data Source button.
AppWizard step 3 figure shown in below is about support for object linking and
embedding and Active-X features. You can specify whether your application supports
OLE compound document functionality as a server, container, mini-server, or container
-server. You can also specify ActiveX document server support and add automation
server and ActiveX control container support; the latter is important if you wish to use
ActiveX controls in your applications dialogs.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
5/16
Visual C++ 6.0 IDE Tools Page 35
If you select compound document support, you can also specify compound file support .If
you select this option, your applications objects will be saved in the compound file format,
which allows load on demand and incremental saves (at the expense of the large file
size).
Depending on which OLE and Active X features you select, the AppWizard may generateadditional classes for your application. For OLE servers, these additional classes include
CInPlaceFrame (representing the frame-window during in-place editing), and a
COleServerItem derived class representing the server object in container applications.
For OLE containers, a new COleClientItem derived class is added, representing OLE
server items in the containers. In both cases, the base class of your applications
document class is also modified. It is derived from COleDocument in the case of
containers and COleServerDocin the case of servers or the container-servers.
Step 4 of AppWizard as shown in figure below contains a variety of miscellaneous
options. The check boxes for toolbar supports, status bar supports, and support for 3-D
controls require little explanation.
If you clear the printing and print preview of the checkbox (it is set by default), yourapplication not have a print or a print preview command in its file menu, nor will it provide
support for print preview mode. It is generally a good idea to leave this box checked even
if you do not wish to provide the printing the commands in the file menu as long as you
intend to use the printing and print preview-related features of MFC.
Setting the Context-Sensitive-Help checkbox adds a skeletal help project file and help
topic files to your application. It also adds the batch file makehelp.bat that can be used to
regenerate your project help file.
Adding messaging API (MAPI) support your application means two things: First, your
application will be linked with the MAPI libraries; second, your application will have a
Send menu item in its File menu. Often this is all you need to provide minimal MAPI
support for compatibility with Windows 95 application requirements
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
6/16
Page 36 Visual C++ 6.0 IDE Tools
Setting the windows Sockets check box adds WinSocklibraries and header files to your
project. However, you are responsible for adding any specific WinSock functionality.
Of particular interest in AppWizard step 4 is the advanced option dialog, invoked when
you clicked on the Advanced button. Through this dialog, you can specify a variety of
additional options that affect your applications and execution in subtle ways.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
7/16
Visual C++ 6.0 IDE Tools Page 37
Step 5 of AppWizard as shown in figure below enables you to specify two simple options:
whether or not the AppWizard -generated skeleton source should contain comments, and
whether the MFC Library should be linked to your project as a static library or a DLL.
Usually, specifying source file comments is a good idea. In addition to providing
meaningful explanations in your code, the AppWizard also generates TODO comments,
which indicate those points in your code that you need to complete or modify manually.
The final in the AppWizard process, step 6 as shown in figure lists the classes the
AppWizard is about to create for your application. You can also modify some aspect of
class creation at this stage.
To complete the AppWizard process, click the finish button. This displays the new project
information dialog (incidentally, giving you one more chance to back out and cancel the
AppWizard procedure); this dialog displays information about the skeleton project. This
information is also saved in your project directory as your projects Readme.txt file
The class generated for a basic single-document-based application includes a Document
class, a View class, a FrameWindow class, and a CWinApp-derived class representing
the application.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
8/16
Page 38 Visual C++ 6.0 IDE Tools
After selecting OK AppWizard generates source code, if you compile and build you will
get the output as shown below.
Tip :When you are working with multiple projects and configurations, consider using the full
Build toolbar rather than the Build MiniBar. The Build toolbar contains drop down list
box controls that allow you to switch between projects or configuration quickly and easily.
These controls also remind you which project of configuration you are currently working
on.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
9/16
Visual C++ 6.0 IDE Tools Page 39
Dialog-based MFC Applications
The AppWizard process for creating dialog-based MFC application is much shorter than
creating document-based application. Selecting a Dialog based application in AppWizard
step 1 and clicking on the next button takes you to step 2 of a four-step process.
The about box option in this steps adds an About command to the dialog control menu;
note that the dialog will not have a menu bar. The Context-sensitive Help option addsAppWizard generated skeletal help support in the help form of a help project file, topic
files, and the makehelp.bat script for regenerating your applications help file. The 3D
controls option needs no explanation.
You can also specify automation and Active-X control support. Select the latter option if
you wish to use Active-X controls in the dialog.
The Windows Sockets option adds WinSock header and library files to your project;
however, it is up to you to implement any specific WinSockfunctionality.
You can also specify the title of your application; this text will be displayed in the title bar
of the application system dialog box.
Step 3 of the AppWizard process for dialog-based application id identical to step 5 for
document-based application. Similarly step 4 for dialog-based application is the same asstep 6 for document-based ones; however, the list of generated classes is different as
shown in figure below. Only two classes are created: one representing the application
object, the other representing the applications dialog.
In many cases, you may find that a dialog-based AppWizard-generated skeleton
application lacks the features that you wish to see in your program. In such cases,
consider using an SDI application based on the CFormViewclass.
Using AppWizard to create MFC -based DLLs
If you use the AppWizard to create an MFC-based DLL skeleton, you are presented with
a one-step procedure where you can specify your DLLs characteristics as shown below.
The first set of options is where you specify how the DLL should be linked with the MFC
library. Linking statically is the most expensive method in terms of disk space and
memory requirements .The least expensive is creating an MFC extension DLL; however,
these DLLs can, in turn, be called from any application.
By setting the automation check box, you enable support for using your DLL as an
automation inproc server (An inproc server is server that execute in the process space of
the client application, as opposed to using a remote procedure call mechanism for
communicating with the client.)
Adding WinSock support enable compiling and linking with the WinSock header and
library files; however, you must add your own implementation of any WinSock -specific
functionality.
Finally, you can also specify if you wish to see AppWizard-generated source comments in
your DLL.
Custom AppWizard
The custom AppWizard enables you to create custom AppWizards (and if terms like
AppWizard-generated AppWizard project skeleton confuse you). A custom AppWizard
can be used on the standard AppWizard for MFC applications or DLLs; it can also be
based on an existing project or contain only custom steps you define. If you specify that
your custom AppWizard be based on an existing project, the second step of the custom
AppWizard lets you select with the AppWizard to use. If your custom AppWizard is to be
based on an existing project, you can specify the projects path in the second step. For
custom AppWizard consisting entirely of custom steps, step 2 of the Custom AppWizardis unavailable.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
10/16
Page 40 Visual C++ 6.0 IDE Tools
Using the Component Gallery
Many AppWizard options can also be added to a project through the component gallery.
For example, you can add MAPI support, clipboard support, or support for Active X
controls to an existing project using the appropriate components from your own project to
add support for specific features to your application.
ClassWizard
The ClassWizard is a fundamental tool in the Visual C++ development system; through
this tool, you can manipulate your applications CCmdTarget-derived classes in a variety
of ways.
The ClassWizard presents itself in the form of a dialog with five pages.
The first of these pages, the Message Map page, enables you to define message-handler
functions for a variety of events, including WM_COMMAND messages generated by
controls in dialogs. The Message Maps is also where you specify your implementation for
many overridable functions.
At the member variable page, you can add member variables that are associated with
dialog controls. Two types of member variables can be added for each control: variables
associated with the control object itself. A control can have one variable of each type;
however, many kinds of controls do not support variables representing their value. If the
member variable represents a control in an ActiveX controls property page, you can alsoassociate an ActiveX control property with the variable.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
11/16
Visual C++ 6.0 IDE Tools Page 41
The automation page presents the selection of automation methods and properties to
classes that support automation. For Active-X controls, you can add stock method and
properties in addition to user-defined ones. You can also specify the level of data binding
that specific properties of an Active-X control support.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
12/16
Page 42 Visual C++ 6.0 IDE Tools
The ActiveX event page is specific to ActiveX controls and lets you specify which ActiveX
events the control may generate. Adding an ActiveX event also adds a firing function for
the event. You can also stop event to your ActiveX control.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
13/16
Visual C++ 6.0 IDE Tools Page 43
The Class Info page shoes some general information about classes. It can also be used
to modify the behavior of ClassWizard as related to this class, by enabling you to change
the message filter the ClassWizard applies when displaying the classs message map
and by setting up or changing the foreign class associated with this class.
A new class can be added to the project by clicking the New Class button. New classes
can be added from scratch, can be generated from a type library, or can be added from
an existing header and implementation files. Note that you can only add classes that are
derived from base classes that ClassWizard recognizes, other types of classes can be
added to your project manually but will not be visible in Class Wizard.
Class Information is stored in the class information file. Although usually this file should
not be modified manually, Exception to this rule is when you implement your own set of
DDX / DDV functions and want to have ClassWizard support for them.
So now you are familiar with the wizards which are frequently used while working with
Visual C++ 6.0. AppWizard is used only during new project workspace creation. It gives
source code for Application framework. There are two ways to add or edit your code. Add
manually, or with the help of ClassWizard.
Control Bars
Tool Bars
Status Bars
Dialog Bars
Windows 95 has unleashed a slew of new common controls that really liven of applications and
give them the modern Windows 95 look and feel. The common controls are all stored in a
Windows DLL named COMMCTRL.DLL. A control bar is usually a child window of a parent frame
window. Class CControlBar provides the common functionality of all toolbars, status bars anddialog bars.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
14/16
Page 44 Visual C++ 6.0 IDE Tools
Tool Bars
A toolbar is a control bar that displays a row of bitmapped buttons that activate commands.
Pressing a toolbar button is equivalent to choosing a menu item. The buttons can be
configured to appear and behave as push buttons, radio buttons, or check boxes. A toolbar is
usually aligned to the top of a frame window, but an MFC toolbar can be made dockable or
floating. A toolbar can display tool tips as the user moves the mouse over the toolbarsbuttons. MFC supplies class CToolBarto manage toolbars.
Displaying a ToolBar is a three-step process
1) Create a toolbar resource with each button having a unique ID.
2) Call Create member function of the CToolBar class this creates a CToolBar
object.
3) Call LoadToolBarmember function of CToolBar class this displays the toobar
on the screen.
Following code creates and displays a toolbar
// SampleWnd.h
class CSampleWnd:public CFrameWnd{
CToolBar* tb;
public:
int OnCreate(LPCREATESTRUCT);
DECLARE_MESSAGE_MAP( )
};
// SampleWnd.cpp
BEGIN_MESSAGE_MAP(CSampleWnd, CFrameWnd)
ON_WM_CREATE( )
END_MESSAGE_MAP( )
int CSampleWnd :: OnCreate(LPCREATESTRUCTlpCreateStruct)
{
tb = new CToolBar;
tb->Create ( this );
tb->LoadToolBar ( IDR_TOOLBAR1 );
EnableDocking ( CBRS_ALIGN_ANY );
Tb-> EnableDocking ( CBRS_ALIGN_ANY );
DockControlBar ( tb );
return TRUE;
}
Status Bars
A status bar is a control bar that contains text-output panes, or indicators. The output panes
are commonly used as message lines and as status indicators. Message line includes the
command help-message lines that explain the selected menu or toolbar command in the
leftmost pane of the default status bar created by AppWizard. Status indicator includes the
SCROLL LOCK, NUM LOCK, and other keys. Status bars are usually aligned to the bottom of
a frame window. MFC class to manage status bar is CStatusBar.
The Status bar can also display dynamic messages like row and column numbers in a word
processor or X and Y coordinates in a graphics editor application. To displays messages in a
particular pane use SetPaneTextfunction of CStatusBar class.
Following code creates a status bar with four pane a blank stretchy pane, NUM lockindicator, CAPS lock indicator, & SCROLL lock indicator. The panes are numbered from 0.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
15/16
Visual C++ 6.0 IDE Tools Page 45
// SampleWnd.h
class CSampleWnd:public CFrameWnd
{
CStatuaBar *sb;
CToolBar *tb;
public:
int OnCreate(LPCREATESTRUCT)
void OnMouseMove(UINT i, CPoint pt)
DECLARE_MESSAGE_MAP( )
};// SampleWnd.cpp
BEGIN_MESSAGE_MAP(CSampleWnd, CFrameWnd)
ON_WM_CREATE( )
ON_WM_MOUSEMOVE( )
END_MESSAGE_MAP( )
int CSampleWnd :: OnCreate(LPCREATESTRUCT
lpCreateStruct)
{
tb = new CToolBar;
tb->Create(this);
tb->LoadToolBar (IDR_TOOLBAR1);
EnableDocking ( CBRS_ALIGN_ANY );
tb->EnableDocking ( CBRS_ALIGN_ANY );
DockControlBar ( tb );
sb = new CStatusBar;
sb->Create(this);
sb->SetIndicators(indicators, sizeof(indicators)/sizeof(int));
return TRUE;
}
void CSampleWnd :: OnMouseMove(UINT i, CPoint pt)
{
char str[20];
sprintf(str, X=%d, Y=%d, pt.x, pt.y);
sb->SetPaneText(0, str);
}
Dialog Bars
A dialogbar is a control bar, based on a dialog-template resource, with the functionality of a
modeless dialog box. Dialog bars can contain any Windows control. Dialog bars can be
aligned to the top, bottom, left, or right side of a frame window. MFC supports dialog bars with
class CDialogBar.
Following are the steps to display a dialogbar
1) Create a dialog bar resource with the desired controls from the control palette.
2) Call the Create member function of the CDialogBar class.
SEED Infotech Ltd.
-
7/27/2019 3 Visual C++ 6.0 IDE Tools
16/16
Page 46 Visual C++ 6.0 IDE Tools
Following code creates and displays a toolbar
// SampleWnd.h
class CSampleWnd:public CFrameWnd
{
CDialogBar *db;
public:int OnCreate(LPCREATESTRUCT);
DECLARE_MESSAGE_MAP( )
};
// SampleWnd.cpp
BEGIN_MESSAGE_MAP(CSampleWnd, CFrameWnd)
ON_WM_CREATE( )
END_MESSAGE_MAP( )
int CSampleWnd :: OnCreate(LPCREATESTRUCT
lpCreateStruct){
db = new CDialogBar;
tb->Create(this, IDD_DIALOG_BAR, CBRS_TOP,
ID_VIEW_MYDIALOGBAR);
return TRUE;
}
Summary
There are two types of application created through AppWizard Document basedand Dialog based.
Single document based application can present a single file to the user at a time
while Multiple document based application can present several documents.
AppWizard allows you to specify the language of your application.
ClassWizard is a fundamental tool through which you can manipulate your
applications CCmdTarget-derived classes in a variety of ways.
ClassWizard is used to add message-handlers and member variables to your
class.
CControlBar provides the common functionality of all toolbars, status bars and
dialog bars.
MFC supports ToolBar, StatusBar and DialogBar with CToolBar, CStatusBar and
CDialogBar class respectively.
Quiz1) Which tool do you normally use to start a new MFC-based application?
2) Which are the types of application created by AppWizard?
3) Which tool is used to add message-handlers?
4) Which class in MFC encapsulates control bars?
5) What are dialog bars? Write a code to create and display dialog bar?
SEED Infotech Ltd.