Implement UI NavigationCreate & integrate toolbarsHandling menu & toolbar selections (02/04/2000)MFC framework -> handlers placed inside class most
closely associated with handler function, e.g. connection to remote DB may be
best handled by application as whole, therefore by the CMyApp class. Handlers added via ClassWizards Message Map tab specify class
that will contain handler, object id that acts as source and message to be
handled. Dynamic updates menus & toolbarsMFC framework provides mechanisms to update appearance &
status of menu commands and toolbars via handlers for user interface update
command messages. Framework generates UI update messages to signal app to
update status of UI in response to menu openings and toolbar button presses.
Message maps of command target objects in command routing searched for
ON_UPDATE_COMMAND_UI entries. Implement handler functions to modify UI appearance.
Framework passes function pointer to CCmdUI object giving access to UI element
associated with handler. This object permits enabling, disabling, checking of
menu items, setting of radio buttons, etc. Implement and Write to Status BarOften updating menu / toolbar appearance not enough to
reflect info. Status bar provides area for further info to be displayed.
AppWizard by default provides CAPS LOCK, NUM LOCK and SCROLL LOC indicators. Status bar support handed by CStatusBar. Indicator info held in array, leftmost position at locn 0.
Each entry in array = resource ID of string table entry. Fist indicator is elastic takes up space not used by
other, right aligned indicators. Entries in string table, usually
ID_INDICATOR_*, associated with corresponding framework indicators. Entry in
table should be of maximum length indicator will be so framework can set out
indicators. To update text in status bar use ON_UPDATE_COMMAND_UI entry
in message map to associate UI entry
with handler function must be added manually as not supported by ClassWizard.
Without handler the framework will disable and blank out the indicator. Indicator text updated via CStatusBar::SetPaneText(). Create new app using MFC AppWizard (05/03/2000)Project is source code + associated
resources and their relationships (build rules, etc.). Independent
settings (debug, release, etc.) for build tools (compiler, linker, etc.) via
Project Settings dialog. AppWizard creates debug and release configurations
initially - can add more. Workspace is container for project(s).
Default = 1 project, can add others. Project dependencies can be defined. Only active
project at a time (name displayed in bold). Project TypesMFC is class based framework Develop
apps, dlls, ActivX controls,etc.. Save time + effort but size + performance
overhead = not suitable for small apps. Requires access to MFC DLLs (either
static or dynamic linking). Win32 is for simple apps without MFC
overhead. Wizards:
·
create
empty or skeleton Window apps - register window classes, create message loop,
basic window processing. ·
create
empty of skeleton dlls - sample code to export classes, functions &
variables. ·
create
empty or skeleton console app ·
create
empty or skeleton static library for linking to executable ·
can
include MFC support (take advantage of strings, collections, etc. ATL is templates for small, fast, COM
objects. Create COM server, dll or exes. Can add ATL com objects to project -
include simple objects, transaction services, MMC, etc. Miscellaneous = Not fit into other categories,
e.g. DLL resources for IIS or Cluster Server, Visual Studio add-ins, custom
AppWizards, etc. Create application using MFC AppWizard (12/03/2000)1.
Choose application type (SDI, MDI, Dialog) 2.
Chose DB support 3.
ActiveX technologies - ActiveX isuse of COM to enable component interactivity.
OLE provides compound docs. 4.
Misc features such as toolbars, 3D controls, MAPI, Sockets, etc. 5.
Advanced options - associates a file extension with the app and specify display
characteristics (width of border, etc.) 7.
Project style - type of presentation (standard or Explorer like), generation of
comments and static / dynamic MFC link 8.
Adjust names of classes generated and their inheritance Create and edit UI objects with resource editors (26/03/2000)App & doc resourcesApp & doc
icons
To
meet certification requirements must provide both standard (32*32) and small
(16*16) icons for application and associated document type. MFC
framework automatically provides default icons for you. Application
resources (icons, menus, etc.) have numeric resource identifier (resource ID). EditorsGraphics Editor Part of IDE use
to edit icons, plus other bitmaps, jpgs, etc.
Application
Menuspermit convenient + consistent grouping of commands.
Wizard generates menus appropriate to selections chosen by developer.
Associated with resource ID of IDR_MAINFRAME. Can change menus through menu
editor. Use of & within menu caption specifies shortcut key used in
conjunction with ALT key to quickly select menu. Shortcut
keys (previously accelerator) provide quick access to program
commands available from menu / toolbar, e.g. associate CTRL+U with data upload.
Held in accelerator table manipulated by accelerator editor that maps key
combinations to message identifiers (e.g. ID_DATA_UPLOAD). Toolbars provide easy access to common
commands. AppWizard generates standard toolbar providing access to file and
edit commands. Toolbar resource associated with bitmap containing button
images, additional bitmap files created for each toolbar defined. Images in
toolbar of same size, usually 16*15. Bitmap image contains buttons side by side
in resource id order for this reason use provided graphic editor (displays
one button at a time). Each button has associated command identifier. Add Message Handler for event using ClassWizardOnOK() = example of control notification message handler for
BN_CLICKED message of IDOK control. Different sets of notification messages associated with
different controls Message Maps tab of ClassWizard provides reference to all
those available. Control notification
messages prefixed by abbreviation for control type followed by an N:
ClassWizard add macros to message map to handle notification
messages for above control types. Macros constructed by prefixing message ID
with ON_, e.g. handler for EN_UPDATE for IDC_USERID results in: ON_EN_UPDATE(IDC_USERID,
OnUpdateUserid) Note, BN_CLICKED for IDOK and IDCANCEL mapped directly by
overridden versions of OnOK and OnCancel no manipulation available. Creating data input forms and dialog boxesCreating Dialog Box using dialog editor (03/04/2000)Child window of main app window display or retrieve status
info. Contains controls (small, standard window objects) through
which info displayed/manipulated. Two types ·
Modal
take control of interface. Require closure of box before use of app can
continue. Example = apps About dialog. ·
Modeless
do not take control of app interface, can work on other areas of app without
closing dialog. Less common than modal. Example is Properties dialog box used
within resource editor of IDE. Property
sheet = special dialog box. Presents user with tabbed, index card like
selection of pages within single frame. Creating dialog box templateUse dialog editor to create dialog box template reusable
app resource that is binary description of dialog box + its controls layout. Template edited by resource editor. Each control within template (including itself) has
associated identifier IDD_* for dialog, IDC_* for control. When using controls within dialog box, only one item has
focus indicated by outline around control. Select control with mouse or TAB key. Specify TAB order
(sequence of control selection) within dialog editor. Creating dialog box classClass representing dialog box within your program, derived
from CDialog. Contains member variables representing controls and data items
within dialog box + methods to handle events arising from user interactions
with dialog. Creating dialog box class simplified by ClassWizard. To create class open from dialog box template, launch
ClassWizard that will prompt for new class to be created (as none is currently
associated with template). Displaying dialog boxAchieved by calling CDialog::DoModal(). Default handlers for
OK and Cancel buttons via CDialog::OnOK() and CDialog::OnCancel(). Example
of creation: { CAboutDlg
aboutDlg; AboutDlg.DoModal(); } Modeless dialogs handled differently. Dont call
CDialog::DoModal(), instead call CDialog::Create() passing in resource ID of
dialog box template. Use ShowWindow() to show and hide the dialog box. Modal dialogs usually created as required, typically on
stack. Modeless dialogs (e.g. toolbars) usually last for the lifetime of the
application and hence are created at application instantiation. Can make window always appear above others by ensuring it
has WS_EX_TOPMOST style set. Can achieve this through the CWnd::SetWindowPos()
function (added into the Create() function). Has side effect of making dialog
appear above all windows in system (not just those of the application). Resolve
this by hiding dialog when application looses focus achieve this by adding
handler for WM_ACTIVATEAPP message. Common dialog classesMFC supplies several
classes derived form CDialog to handle common tasks; CColorDialog, CFileDialog,
CFindReplaceDialog, CFontDialog, CPrintDialog. Creating property sheets by using ClassWizard3 main parts; containing dialog box, 1+ property pages, tabs
at top of each page used to select page. Used when have number of groups of similar settings /
options, e.g. property sheet in MSDEV IDE. Implemented by two classes CPropertySheet for containing
dialog box and CPropertyPage for individual pages of property sheet. Recipe: ·
Create
dialog template for each property page. Aim for consistent layout and size.
Ensure thin style, child and disabled properties set. Caption for dialog
template appears on the page tab. ·
Derive
classes from CProperyPage for each dialog. ·
Create
member variables +DDX/DDV to hold values for property pages. ·
Create
CPropertySheet object in source code ·
Create
objects for each of the property pages. ·
Add
each page to the sheet by calling the CPropertySheet::AddPage() function ·
Bring
in to use via DoModal or Create functions depending on modal nature. For
modal property sheets the framework provides OK, Cancel and Apply buttons and
DDX/DDV for control on each page. If additional controls required on property
sheet then use class wizard to generate class derived from CPropertySheet. For modeless property sheets it is necessary to provide own
CPropertySheet derived class as the Create() function does not create default
controls for the sheet. Handling Apply
Button
The Apply button allows users to exchange and validate
changes made without closing property sheet useful if wanting to save changes
made on one page before proceeding to next. By default Apply button is unavailable. To make available
after data changed, call to CPropertyPage::SetModifed(TRUE) is required. Validating user input
Dialog data exchange (DDX) and validation (DDV)DDX = easy way to set and retrieve control values within
dialog. DDV = easy validation of data entry within dialog box. DDX and DDV implemented within dialog class, architecture
similar to message maps. DDX and DDV functions = global MFC functions. A number of
standard DDX and DDV functions provided for common dialog components. Member variables within dialog class represent controls with
global MFC functions used to transfer values between the two. Framework DDX/DDV
ClassWizard implements basic DDX/DDV architecture. It will: ·
Add
member variables to class definition (within AFX comments) ·
Initialise
member variables in constructor (within AFX comments) ·
Add
DDX functions to transfer values between variables and controls (within AFX
comments in DoDataExchange()) ·
Optionally
add DDV functions to validate data entry (within AFX comments in
DoDataExchange()) Overriden version of DoDataExchange() provided by
ClassWizard for dialog class. Both DDX and DDV functions take a pointer to a CDataExhange
object (represents data exchange context including direction of exchange) as
their first parameter. DoDataExchange() called by CWnd::UpdateData(). UpdateData()
takes parm indicating direction of exchange (set or read values) which is
passed to DDX/DDV functions via CDataExchage object. Can call UpdateData() at
any point to perform data exchange. Custom DDX/DDVCan define own DDX/DDV functions first parm always pointer
to CDataExchange object. Extra parms can be provided as required by function. All custom DDX/DDV function definitions and calls must be
placed outside AFX comment blocks. DDV functions must always be placed directly after DDX
functions to which they refer. Control InitialisationSome
controls require more initialisation than can be easily achieved via DDX functions,
e.g. filling list boxes with info determined at run time. Can achieve by overloading CDialog::OnInitDialog(). Note,
OnInitDialog calls UpdateData() and hence DDX/DDV functions. OnInitDialog called by framework after control creation but
before display provide opportunity to populate with data. Enabling / Disabling ControlsTo minimise DDV complexity controls on dialogs should be
disabled until they can be realistically used for example when connecting to
DB only allow connect button o be clicked when name of database supplied
elsewhere on dialog. Controls derived from CWnd, therefore use EnableWindow() to
set control availability. Use MFC AppWizard to create ISAPI DLLISAPI Server ExtensionsServer-side program
running in response to client request. Implemented as DLL loaded by IIS,
browser can run program by specifying its name in the url, as in: http://myserver/apps/charts.dll Specific functions can be invoked by appending their name to
the function name as follows: http://myserver/apps/charts.dll?GetChart All ISAPI dlls must define default function to be called
when client does not specify one. Parameters passed in similar way: http://myserver/apps/charts.dll?GetChart?Fund=ASRC Can link ISAPI dlls into HTML forms via the ACTION statement
for FORMS, which specifies what action to carry out when submitting a form. ISAPI server extensions based on CGI. Without altering
specifications, ISAP permits any browser to load and run extension dll. As DLLs
execute in same process space as webserver they are quicker than CGI scripts
which require separate processes. CreatingUse MFC ISAPI
Extension Wizard to create server extension object. Creates single class (name
derived from project name, e.g. CMySampleExtension) derived from CHttpServer.
Add member function to this class to implement DLL exported functionality. MFC uses a parse map (declared in the .h and implemented in
.cpp) to map DLL functions to member functions of the CHttpServer derived
class. One of members marked as default by DEFAULT_PARSE_COMMAND macro. All ISAPI extension functions take a pointer to CHttpServerContext
as first parm provides details on client / server connection (a separate
class created for each connection). Use this class to obtain access to clients
HTTP request, insert entries (using << operator) into file sent back to
client, etc. Sample parse map: BEGIN_PARSE_MAP(CMyServerExtension, CHtpServer) ON_PARSE_COMMAND(Default, CMyServerExtension, ITS_EMPTY) DEFAULT_PARSE(CMyServerExtension) ON_PARSE_COMMAND(GetColour, CMyServerExtension, ITS_PTR) ON_PARSE_COMMAND_PARAMS(Colour) END_PARSE_MAP(CMyServerExtension) Note, the GetColour function takes a parameter named colour.
The parameters and their types handled by the function are indicated by the
third (and subsequent) entries of ON_PARSE_COMMAND, with their names specified
on subsequent ON_PARSE_COMMAND_PARAMS lines. Extension DLLs loaded by IIS at first client request. ISAPI Filters Sit between client
and HTTP server. Enhance IIS with custom features such as HTTP request logging,
encryption, compression, etc. Loaded when IIS service started. Can only
configure IIS 4.0 to use filters, not supported by Personal Web Server (PWS). Filters receive notification from server when selected
events occur, such as starting to process client request, sending data to
client, writing information to log files, etc. Filter will have access to data
associated with event, e.g. if data being sent to client then filter has access
to data about to be sent and can modify it (compress, encrypt, etc.). CreatingUse MFC ISAPI
Extension Wizard to create filter object sits between network connection of
client and HTTP server. Creates single class (name derived from project name,
e.g. CMySampleFilter) derived from CHttpFilter. Member functions have been
added for each notification specified in step 3 of the Wizard these overload
those specified by CHttpFilter. Extend these functions to define filter
behaviour. Class also defines
GetFilterVersion() which specifies what notifications the class is interested
in. The server uses this function to ensure it does not send unnecessary
notifications to the filter. If you add
additional handler functions later, must update this function to receive them. Functions receive
data structures containing information about event. Also receive pointer to
CHttpFilterContext object containing info about current client connection +
methods to read and modify its values. Incorporate Dynamic HTML in ApplicationDHTML = extension to HTML exposing web page + its elements
as scriptable objects. Able to: ·
Modify
web page text ·
Modify
style sheet elements specifying how text displayed ·
Animate
text and images ·
Respond
to user actions such as mouse moves or clicks ·
Validate
input before submitting to server Automatically
reformats document no need to reload. Does not require additional application
support DHTML documents are self-contained, use style sheets to specify
format / appearance and small blocks of script to manipulate HTML tags,
attributes, styles, etc. Based on existing HTML standards. Some DHTML features not visible
in non-DHTML browsers. Follow basic guidelines to ensure contents always
visible, even if formatting wrong. DHTML Object ModelAny HTML page loaded
by IE4 (or later) held in representation accessible via DHTML object model. Can
access + manipulate anything within document via model. HTML elements
represented as individual objects held in collections (similar to those
provided by MFC). Iterate collections (such as anchors, applets, frames
) to
gain access to individual elements. Model exposes user actions (key press, mouse click, etc.) as
events. Create event handlers to intercept and process them. Can identify individual elements on page using ID attribute
as in <H3 ID=MyHeading>Welcome to Dynamic
HTML!</H3> which can then be modified by scripts within document, for
example to turn text green the following piece of java could be used MyHeading.style.color= green. WebBrowser ControlActiveX control used to incorporate web pages within
application. It is component of Internet Explorer implementing the main window.
Supports hyperlinks, URL navigation, maintains security, history and favourites
list. Encapsulated within MFC by CHtmlView. Inserting control in project creates CWebBrowser2 class, a
wrapper for the IWebBrowser2 automation interface, through which properties and
methods can be accessed in C++ like fashion. Preferred way of using control is to derive view from
CHtmlView (specify during AppWizard creation process). Provides web browser
functionality within document/view architecture. Access Object ModelVery easy from HTML refer to object by name as in document.bgColor = hotpink. This functionality provided by
Internet Explorer interpreter parsing HTML script and calling apparopriate
automation interfaces on WebBrowser control. In C++ access DHTML object model
by using Automation interfaces directly. DHTML object model exposed through interfaces beginning
HTML, as in IHTMLDocument, IHTMLWindow, IHTMLElement, etc. The CHtmlView class
provides GetHtmlDocument() which return IDispatch to HTML document currently
being displayed. From here can access the IHTML* interfaces. HTML ResourcesCan include HTML resources in project just like bitmaps,
dialog templates, etc. Provides safe + convenient way to distribute HTML pages
used by application. |