You are on page 1of 57

UNIT II VISUAL C++ PROGRAMMING INTRODUCTION

Application Framework MFClibrary MFC class hierarchy - Visual C++ Components Event
Handlin MFC Messae processin - Creatin MFC Application! "esources Creatin menus -
dialo based applications - modal and modeless dialo#
Top Level MFC Hierarchy Char
What is MFC Programming?
The Microsoft Foundation Class Library (MFC) is an "application frameor!" for programming in
Microsoft Windos" Written in C##$ MFC pro%ides much of the code necessary for managing
indos$ menus$ and dialog bo&es' performing basic input(output' storing collections of data
ob)ects' and so on"
The MFC frameor!* +
The MFC frameor! is a poerful approach that lets you build upon the or! of e&pert
programmers for Windos" MFC shortens de%elopment time' ma!es code more portable'
pro%ides tremendous support ithout reducing programming freedom and fle&ibility' and gi%es
easy access to "hard to program" user+interface elements and technologies$ li!e ,cti%e
technology$ -L.$ and /nternet programming" Furthermore$ MFC simplifies database
programming through 0ata ,ccess -b)ects (0,-) and -pen 0atabase Connecti%ity (-01C)$ and
netor! programming through Windos 2oc!ets" MFC ma!es it easy to program features li!e
property sheets ("tab dialogs")$ print pre%ie$ and floating$ customi3able toolbars"
$%&'
The Microsoft Foundation Class (MFC) Library
The Windos MFC Library consists of a hierarchy of C## classes designed to facilitate
Windos programming" To see a conte&t sensiti%e map (hot+lin!ed diagram) of the
entire MFC class hierarchy$ search the online help for "hierarchy chart"")
4sing the MFC library classes offers an alternati%e to using Win56 ,P/ functions" The
folloing diagram illustrates ho a 7isual C## Windos application can use either the
Win56 ,P/ or MFC (or both) to rite a program that tells the computer hardare hat
has to be done*
There are about 688 MFC classes (%ersus 6888# ,P/ functions)" They pro%ide a
frameor! upon hich to build Windos applications" They encapsulate most of the
Win56 ,P/ in a set of logically organi3ed classes"
2ome of the characteristics of MFC are++
9" They offer the con%enience of :.42,1L. C-0.$ so that*
+Many of the tas!s common to all Windos applications are pro%ided by MFC"
+-ur programs can inherit and modify this functionality as needed"
+Therefore e don;t need to recreate these tas!s"
+/n other ords$ MFC handles many clerical details"
(%&'
6" They produce smaller e&ecutables*
+MFC programs are typically 9(5 the si3e of their ,P/ counterparts"
5" They can lead to faster program de%elopment++
+1ut there is a steep learning cur%e$ especially for those ho are not comfortable
ith the ob)ect+oriented programming paradigm"
<" MFC Programs must be ritten in C## and re=uire the use of classes$ so the
programmer needs a good grasp of*
+>o classes are declared$ instantiated$ and used
+.ncapsulation
+/nheritance
+Polymorphism++%irtual functions
T>. MFC CL,22 >/.:,:C>? (2ee online help on ">ierarchy Chart")++
,t the top* C-b)ect ("Mother of all classes")* pro%ides run+time support features li!e
seriali3ation (dis! reading(riting)' all its functionality is inherited by any classes
deri%ed from it"
/mportant deri%ed classes++
CFile* 2upport for file operations"
C0C* .ncapsulates the de%ice conte&t (@raphical 0raing)"
C@di-b)ect* 1ase class for %arious draing ob)ects (bitmaps$ pens$ etc")
CMenu* .ncapsulates menu management"
CCmdTarget* .ncapsulates process of message passing A is the parent of*
CWnd* 1ase class from hich all indos are deri%ed' most common*
CFrameWindo* ("normal" !ind of indo that can contain other indos++the
!ind that e;%e been using)"
C7ie* encapsulates process of displaying data"
)%&'
CWinThread* 0efines a thread of e&ecution"
CWin,pp* Most important class dealt ith in MFC apps++
.ncapsulates an MFC application" Controls the folloing aspects of Windos programs*
2tartup$ initiali3ation$ e&ecution$ and shutdon" ,n application should ha%e one CWin,pp
ob)ect" When instantiated$ the application begins to run"
C0ocument*
.ncapsulates the data associated ith a program"
The primary tas! in riting the code for an MFC program is to create classes"
Most of these ill be deri%ed from one of the MFC library classes"
MFC M.M1.: F4BCT/-B2++
Most of the functions an application ill call are members of an MFC
class"
.&amples* 2hoWindo()++a member of CWnd class"
Te&t-ut()++a member of C0C"
Load1itmap()++a member of C1itmap"
,pplications can also call ,P/ functions directly$ but it;s more con%enient to use MFC
member functions"
MFC @L-1,L F4BCT/-B2++
MFC also defines important "global" functions that are not members of any MFC
class"
They alays begin ith ,f& prefi& (From ,pplication FrameorC2)"
.&ample* ,f&Message1o&()++since message bo&es are predefined indos$ it;s
possible to acti%ate one independently from the rest of an application"
,f& functions are either independent of or span the MFC class hierarchy"
, M/B/M,L MFC P:-@:,M (,PP(W/B0-W ,PP:-,C>)++
The simplest MFC programs contain to classes e must deri%e from the hierarchy*
,n application class deri%ed from CWin,pp++defines the application"
, indo class usually deri%ed from CFrameWnd++defines the application;s main
indo"
.%ery MFC program must ha%e these to classes"
*%&'
M.22,@. P:-C.22/B@ 4B0.: MFC++
Dust as in Win56 ,P/ programs$ MFC programs must handle messages from Windos" /n
the ,P/ case the mechanism is a huge sitch(case statement" MFC uses something
called "message maps$" hich are loo!up tables" .ach table contains entries that consist
of a message number and a pointer to a deri%ed class member message+processing
function" We must declare the message+processing functions and map them to the
specific messages that our application is going to respond to" The mapping is done by
"message+mapping macros"" /n an MFC application most indos use a indo procedure
supplied by the library" The message maps enable the library indo procedure to find
the class member function that corresponds to the current message" (The figures belo
attempt to illustrate the difference beteen ho ,P/ and MFC applications respond to
messages")

&%&'
2P.C/F/C 2T.P2 /B W:/T/B@ , 2/MPL. MFC P:-@:,M (,pp(Windo ,pproach)++
Einclude "af&in"h" ((/ncluding the MFC Class >eader
class MyWnd * public CFrameWnd ((Create a Windo Class by /nheriting from
CFrameWnd
F
public*
MyWnd()
F
((Create a Windo
Create(B4LL$"2imple Windo + MFC"$ W2G-7.:L,PP.0W/B0-W$
rect0efault$B4LL$B4LL$B4LL)'
H
((Function for Painting the Windo
af&Gmsg %oid -nPaint()
F
CPaint0C dc(this)'
dc"Te&t-ut(988$988$"This is a 2imple Windo")'
H
0.CL,:.GM.22,@.GM,P() H'
((Process the Messages Maps
1.@/BGM.22,@.GM,P(MyWnd$CFrameWnd)
-BGWMGP,/BT()
.B0GM.22,@.GM,P()
class My,pp*public CWin,pp ((Create an ,pplication Class
F
1--L /nit/nstance() ((2tarting point of the Class
F
MyWnd IMyWnd-b)'
MyWnd-b) J ne MyWnd'
mGpMainWndJ MyWnd-b)'
mGpMainWnd+K2hoWindo(9)'
return T:4.'
H
H'
My,pp a' ((Create an ob)ect for the ,pplication Classs
+%&'
," 0.CL,:,T/-B2 ("CPP) L2ee P:-@9"CPP for simple e&amplesM*
9" 0eclare a indo class deri%ed from CFrameWnd (e"g"$ CMainWin)'
Class Members*
The constructor
Message+processing function declarations Le"g"$ af&Gmsg %oid -nPaint()M"
0.CL,:.GM.22,@.GM,P() macro to*
+allo indos based on this class to respond to messages'
+declare that a message map ill be used to map messages to functions'
This should be the last class member declared"
6" 0eclare an application class deri%ed from CWin,pp (e"g"$ C,pp)*
/t Must o%erride the CWin,pp;s %irtual /nit/nstance() function"
+This function is called each time a ne instance of the application
is started' i"e"$ hen an ob)ect of this class is instantiated"
1" /MPL.M.BT,T/-B ("CPP) L2ee P:-@9"CPP for simple e&amplesM*
9" 0efine the constructor for the class deri%ed from CFrameWnd (CMainWin)++
/t should ma!e a call to member function Create() to create the indo"
+This does hat CreateWindo() does in ,P/ programming"
6" 0efine the message map for the class deri%ed from CFrameWnd (CMainWin)++
1.@/BGM.22,@.GM,P(oner$ base)
Llist of "message macros" Le"g"$ -BGWMGC>,:()M
.B0GM.22,@.GM,P()
5" 0efine the message+processing functions declared in 9 abo%e++
(There are none in the P:-@9 e&ample")
<" 0efine the /nit/nstance() o%erriding function in the class deri%ed from
CWin,pp (C,pp) N
2hould ha%e initiali3ation code for each ne instance of the application*
+Create a CMainWin ob)ect ++K a pointer to program;s main indo"
(This is used li!e hWnd in ,P/ programs to refer to the indo")
'%&'
+/n%o!e the ob)ect;s 2hoWindo() member function"
+/n%o!e the ob)ect;s 4pdateWindo() member function"
+Must return non+3ero to indicate success"
LMFC;s implementation of WinMain() calls this function"M
,t this point the nature and form of the simple indo and application ha%e been
defined$ but neither e&ists until an application ob)ect deri%ed from CWin,pp (C,pp) is
instantiated"
O" Create an instance of the application class (C,pp)*
This causes WinMain() to e&ecute++it;s no a part of MFC LW/BM,/B"CPPM"
WinMain() does the folloing*
+Calls ,f&Win/nit()$
hich calls ,f&:egisterClass() to register the indo class"
+Calls C,pp**/nit/nstance() Lthe %irtual function o%erridden in 6 abo%eM$
hich creates the indo and shos it"
+Calls CWin,pp**:un()$
hich calls CWinThread**PumpMessage()++
hich contains the @etMessage() loop"
+,fter this returns (i"e"$ hen the WMGP4/T message is recei%ed)$
,f&WinTerm() is called$ hich cleans up and e&its"
T>. P:-@9 0.CL,:,T/-B2 (P:-@9"CPP)++
P:-@9"> )ust declares the CMainWin class deri%ed from CFrameWnd$ its constructor
CMainWin() and its message map" Bote that this simple application does not respond to
any messages$ so there are no message handler functions to declare" /t then declares
the C,pp class deri%ed from CWin,PP and declares that the /nit/nstance() %irtual
function base class member ill be
o%erridden"
T>. P:-@9 /MPL.M.BT,T/-B (P:-@9"CPP)++
9" P:-@9"CPP first defines the CMainWin constructor$ hich simply ma!es a call to
the member function Create()" Whene%er a CMainWin ob)ect is instantiated$ this
ill cause a indo ith the title ",n MFC ,pplication 2!eleton" to be created"
Bote that setting the first parameter to B4LL causes most of the
characteristics of the indo that is created to ta!e on their default frame+
style %alues" (2ee online help on CFrameWnd**Create")
,%&'
6(5" P:-@9"CPP ne&t defines an empty message map using the macros
1.@/BGM.22,@.GM,P() and .B0GM.22,@.GM,P()" .%en though the application
doesn;t respond to any messages$ e need to define the message map" /n almost all MFC
applications$ there ill be se%eral message+mapping macros in the message map"
<" P:-@9"CPP ne&t defines the o%erride to the C,pp;s /nit/nstance() member function"
First a ne CMainWin ob)ect is instantiated$ and this gi%es us a pointer to the resulting
indo" Bote that in our CMainWin constructor (see abo%e) e made a call to Create()$
hich creates the indo$ so at this point our frame indo has been created" We then
use the pointer to the resulting indo to in%o!e the 2hoWindo() member function$
hich causes the indo to display itself" ,nd then the 4pdateWindo() member
function causes a the indo to update its client area" Bote that these are the same
steps that ere folloed in ,P/ programming in the WinMain() function after the
indo as created by CreateWindo()"
O" Finally a C,pp ob)ect is instantiated" ,s described in the "/MPL.M.BT,T/-B"
section abo%e$ this causes the WinMain() Lno buried in MFCM to e&ecute$ hich$ in turn$
causes our C,pp**/nit/nstance() to run++so the indo appears" ,nd$ as described
abo%e$ the message loop begins" When this application is built and run$ e can %isuali3e
the folloing se=uence of e%ents occurring*
C,pp ob)ect is created ++K
MFC;s WinMain() e&ecutes++K
:egisters class (default)
Calls our C,pp**/nit/nstance()++K
-ur o%erride creates a CMainWin ob)ect++K
The CMainWin constructor calls Create() hich creates the indo
-ur o%erride calls the indo;s 2hoWindo() function hich displays it
-ur o%erride calls 4pdateWindo() hich paints its client area
WinMain() continues by calling its :un() function++K
Which calls PumpMessage()++K
Which starts the message loop"
-%&'
CWin,pp* The ,pplication Class
The main application class in MFC encapsulates the initiali3ation$ running$ and termination of an
application for Windos" ,n application built on the frameor! must ha%e one (and only one)
ob)ect of a class deri%ed from CWin,pp" This ob)ect is constructed before indos are
created" (CWin,pp is deri%ed from CWinThread$ hich represents the main thread of e&ecution
for your application$ hich might ha%e one or more threads" /n recent %ersions of MFC$ the
/nit/nstance$ :un$ .&it/nstance$ and -n/dle member functions are actually in class
CWinThread" These functions are discussed here as if they ere CWin,pp members instead$
since the discussion concerns the ob)ect;s role as application ob)ect rather than as primary
thread")
Li!e any program for Windos$ your frameor! application has a WinMain function" /n a
frameor! application$ hoe%er$ you don;t rite WinMain" /t is supplied by the class library and
is called hen the application starts up" WinMain performs standard ser%ices such as
registering indo classes" Then it calls member functions of the application ob)ect to initiali3e
and run the application" (?ou can customi3e WinMain by o%erriding the CWin,pp member
functions that WinMain calls")
To initiali3e the application$ WinMain calls your application ob)ect;s InitApplication and InitInstance
member functions" To run the application;s message loop$ WinMain calls the :un member
function" -n termination$ WinMain calls the application ob)ect;s ExitInstance member function"
The figure 2e=uence of .&ecution belo shos the se=uence of e&ecution in a frameor!
application"
2e=uence of .&ecution* +
-%erridable CWin,pp Member Functions
CWin,pp pro%ides se%eral !ey o%erridable member functions (CWin,pp o%errides these
members from class CWinThread$ from hich CWin,pp deri%es)*
/nit/nstance
:un
$.%&'
.&it/nstance
-n/dle
The only CWin,pp member function that you must o%erride is /nit/nstance"
/nit/nstance Member Function
Windos allos you to run more than one copy$ or "instance$" of the same application" WinMain
calls /nit/nstance e%ery time a ne instance of the application starts"
The standard InitInstance implementation created by ,ppWi3ard performs the folloing tas!s*
,s its central action$ creates the document templates that$ in turn$ create documents$
%ies$ and frame indos" For a description of this process$ see 0ocument Template
Creation"
Loads standard file options from an "/B/ file or the Windos registry$ including the
names of the most recently used files"
:egisters one or more document templates"
For an M0/ application creates a mainframe indo"
Processes the command line to open a document specified on the command line or to open
a ne$ empty document"
:un Member Function
, frameor! application spends most of its time in the :un member function of class CWin,pp"
,fter initiali3ation$ WinMain calls :un to process the message loop"
:un cycles through a message loop$ chec!ing the message =ueue for a%ailable messages" /f a
message is a%ailable$ run dispatches it for action" /f no messages are a%ailable Q often the case
Q :un calls -n /dle to do any idle+time processing that you or the frameor! may need done" /f
there are no messages and no idle processing to do$ the application aits until something
happens" When the application terminates$ :un calls .&it/nstance" The figure The Message Loop
in -n/dle Member Function shos the se=uence of actions in the message loop"
-n/dle Member Function
When no Windos messages are being processed$ the frameor! calls the CWin,pp member
function -n/dle (described in the Class Library :eference)"
-%erride -n/dle to perform bac!ground tas!s" The default %ersion updates the state of user+
interface ob)ects such as toolbar buttons and performs cleanup of temporary ob)ects created
by the frameor! in the course of its operations" The figure The Message Loop illustrates ho
the message loop calls -n/dle hen there are no messages in the =ueue
$$%&'
The Message Loop
.&it/nstance Member Function
The .&it/nstance member function of class CWin,pp is called each time a copy of your
application terminates$ usually as a result of the user =uitting the application"
-%erride .&it/nstance if you need special cleanup processing$ such as freeing graphics de%ice
interface (@0/) resources or deallocating memory used during program e&ecution" The
frameor!$ hoe%er$ pro%ides cleanup of standard items such as documents and %ies$ ith
other o%erridable functions for doing special cleanup specific to those ob)ects"
$(%&'
MFC The Microsoft Foundation Class Library.
2o hat is this MFC Library?
Most definitions ill tell you that the MFC library is the class library for de%elopment of
Microsoft Windos applications"
2o hat is a class library?
, "class library" is a set of standard classes (including properties and methods) for use in C##
program de%elopment"
The most usual )ustification for the e&istence of a class library is'
" they allo program de%elopers to use some one else;s code "
The term reuse in theory e=uates to "ma!es de%elopment easierR"
MFC tries to ta!e this philosophy e%en further and e&tends its claim to
"MFC allos program de%elopers to simplify the tas! of de%elopment of applications for
indos in C##$ both by reuse of standard classes and by building basic s!eleton code" "
/t is of course perfectly acceptable to de%elop for indos using C## ithout the MFC library$
but it is claimed there are %ery fe positi%e benefits for doing soR
Why?
The anser to this =uestion lies in the idea that not only does MFC offer a standard set of
classes to build the basic elements of a indos application it also includes the so called
frameor! that builds a s!eleton application"
This frameor! ta!es aay the tedium of the standard aspects of indos programming i"e"
WinMain("") and the basic WinProc(""")"
The functionality of Winmain("") and WinProc(""") are encapsulated in the basic frameor!
classes of MFC thereby gi%ing most MFC applications a standard feel"
/n ha%ing a standard set of classes it is possible if the de%eloper ants to$ to use the so called
Class Wi3ards to assist in the basic frameor! de%elopment and also to act as a C,2. tool as
ne methods data etc"$ are added to standard classes"
,s an e&ample its possible using the application i3ard to specify a base system design including
$)%&'
Multiple or single 0ocument interfaces
Tool 1ars
2tatus 1ar
.&tensions on data manipulation
.&tensions to -L. design both container and ser%er
Without ha%ing to actually specify any ne code"
MFC and class library ideas also encapsulate the portability of an application de%elopment$ the
industry has already e&perienced the fact that 9S bit MFC applications can be directly migrated
to 56 bits ithout any significant reor! i"e" Win 5"9"& applications ere ported loc! stoc! and
barrel to Win;TO"
.=ually important in today;s /"T" culture MFC or for that matter any other C## class library can
be =uite =uic!ly ported to other processor models$ the only ma)or re=uirement is that the C##
compilers on each conform to the necessary standards"
MFC Evolution
,lthough e cannot change hat as happened$ it is important to loo! at the e%olution of this
particular class library" , great deal of de%elopment or! has ta!en place o%er the last O to S
years$ this means that any code you de%elop using MFC has the benefit of many man years of
effort ensuring that class library functions etc"$ are correct"
-riginally MFC as no more than some %ery simple rapper functionality around the basic
indo ,P/ calls" ,t each subse=uent release additional feature ha%e been added to' enhance
the rapper functionality$ reduce the comple&ity of ,P/ e&tensions such as M,P/$T,P/$ -L.
etc" Pro%ide this frameor! system and simplify its deri%ation"
Today MFC is considered by many as the only method to use for indos applications
de%elopment in C##" -f course it is up to applications de%eloper to ma!e the choice but it is )ust
that a choice" ?ou can use MFC for some aspects of the system but not for others the
fle&ibility is in+built"
4sing MFC is not ithout problems$ there is a %ery steep learning cur%e$ e%en if you are
e&perienced in ;--; design and implementation you still ha%e to understand the architecture of
MFC to use it effecti%ely" The final code si3e of an application e%en if it is using the 0LL
%ersion of the MFC library ill be larger than a comparable de%elopment ithout MFC"
The trade off must be considered carefully before any de%elopment is underta!en using the
MFC route"
$*%&'
MFC Structure and Architecture
/n order to use MFC effecti%ely e need to in%estigate the o%erall architecture"
/n MFC all ob)ect classes are deri%ed from the base class of C-b)ect"
$&%&'
The C-b)ect class pro%ides the ability to
Serialisation' the ability to load and sa%e the ob)ect to (from structured permanent
storage
Runtime Class nformation! the class name its position in the hierarchy can be
e&tracted at run time"
"ia#nostic $ut%ut' ability if in debug mode to use trace info in debug indo
Com%atibility' all ob)ects must be a member of the MFC collection itself"
The actual library itself can be broadly categorised into
9" @eneral purpose' strings files$ e&ceptions date(time and rectangles
6" 7isual -b)ects' indos$ de%ice conte&t$ @0/ functions and dialogues"
5" ,pplication architecture' applications$ documents (the data)$ %ies (on the data)"
<" Collections' lists arrays etc"
O" -L.' specific functionality
S" -01C' specific functionality"
Membership of any one of these basic di%isions is not e&clusi%e' a class can e&ist in more than
one"
.&ample"
The CcmdTarget appears in all e&cept the general purpose"
$+%&'
CCmdTarget is the base class for the Microsoft Foundation Class Library message+map
architecture" , message map routes commands or messages to the member functions you &rite
to handle them.
Cey frameor! classes deri%ed from CCmdTarget include C7ie$ CWin,pp$ C0ocument$ CWnd$
and CFrameWnd" The class CCmdTarget includes member functions that handle the display of
an hourglass cursor" 0isplay the hourglass cursor hen you e&pect a command to ta!e a
noticeable time inter%al to e&ecute"
Messa#e Ma%s
.ach class that can recei%e messages or commands has its on "message map""
The class uses message maps to connect messages and commands to their handler functions"
,ny class deri%ed from class CCmdTarget can ha%e a message map"
, Typical message Map ill ha%e the form
1.@/BGM.22,@.GM,P(CMy7ie$ C7ie)
((FF,FUGM2@GM,P (CMy7ie)
-BGWMGM-42. ,CT/7,T.()
-BGC-MM,B0 (/0G.0/TGCL.,:G,LL$ -n.ditClear,ll)
-BG4P0,T.GC-MM,B0G4/
(/0G.0/TGCL.,:G,LL$ -n4pdate.ditClear,ll)
-BG1BGCL/CC.0 (/0GM?G14TT-B$ -nMy1utton)
((HH,FUGM2@GM,P
.B0GM.22,@.GM,P()
To macros$ 1.@/BGM.22,@.GM,P and .B0GM.22,@.GM,P$ brac!et the message map"
-ther macros$ such as -BGC-MM,B0$ fill in the message map;s contents"
?ou can see that the first argument identifies the message and the second identifies hat to
do ith it i"e" the handler function to call"
,s ith all indos applications it is not necessary to handle all the messages that can be
generated$ MFC in con)unction ith the normal default indos handlers ill ta!e care of those
messages arri%ing for a particular class and that are not handled by that class"
$'%&'
CWinA%%
The CWin,pp class is the base class from hich you alays a indos application ob)ect" ,n
application ob)ect pro%ides member functions for initialising your application (and each instance
of it) and for running the application"
.ach application that uses the MFC classes can only contain one ob)ect deri%ed from CWin,pp"
This ob)ect is constructed hen other C## global ob)ects are constructed and is already
a%ailable hen Windos calls the WinMain function$ hich is supplied by the MFC Library"
2o e must declare our CWin,pp ob)ect at the global le%el" Bormally hen you deri%e an
application class from CWin,pp$ you o%erride the /nit/nstance member function to create your
application;s main indo ob)ect"
2ome of the specific data members are"
mGps3,ppBame 2pecifies the name of the application"
mGh/nstance /dentifies the current instance of the application"
mGhPre%/nstance 2et to B4LL in a 56+bit application"
mGlpCmdLine Points to a null+terminated string that specifies the
command line for the application"
mGnCmd2ho 2pecifies ho the indo is to be shon initially"
mGb>elpMode /ndicates if the user is in >elp conte&t mode (typically
in%o!ed ith 2>/FT#F9)"
mGp,cti%eWnd Pointer to the main indo of the container application
hen an -L. ser%er is in+place acti%e"
mGps3.&eBame The module name of the application"
There are many to many actual methods that can be in%o!ed but it may be of interest to sho
at this point typical Command methods
-nFileBe /mplements the /0GF/L.GB.W command"
-nFile-pen /mplements the /0GF/L.G-P.B command"
-nFilePrint2etup /mplements the /0GF/L.GP:/BTG2.T4P command"
-nConte&t>elp >andles 2>/FT#F9 >elp ithin the application"
$,%&'
CWnd
The @eneric indo class
The CWnd class pro%ides the base functionality of all indo classes in the Microsoft
Foundation Class Library" , CWnd ob)ect is distinct from a Windos indo$ but the to are
tightly lin!ed" , CWnd ob)ect is created or destroyed by the CWnd constructor and
destructor" The Windos indo$ on the other hand$ is a data structure internal to Windos
that is created by a Create member function and destroyed by the CWnd %irtual destructor"
The 0estroyWindo function destroys the Windos indo ithout destroying the ob)ect"
The CWnd class and the message+map mechanism hide the WndProc function" /ncoming
Windos notification messages are automatically routed through the message map to the
proper -nMessage CWnd member functions" ?ou o%erride an -nMessage member function to
handle a member;s particular message in your deri%ed classes"
The CWnd class also lets you create a Windos child indo for your application" 0eri%e a class
from CWnd$ then add member %ariables to the deri%ed class to store data specific to your
application" /mplement message+handler member functions and a message map in the deri%ed
class to specify hat happens hen messages are directed to the indo"
?ou create a child indo in to steps" First$ call the constructor CWnd to construct the CWnd
ob)ect$ and then call the Create member function to create the child indo and attach it to
the CWnd ob)ect"
When the user terminates your child indo$ destroy the CWnd ob)ect$ or call the
0estroyWindo member function to remo%e the indo and destroy its data structures"
The only basic data member of CWnd
mGhWnd /ndicates the >WB0 attached to this
The methods a%ailable ithin CWnd encompass all the ,P/;s that you ould normally associated
ith a Windos application ritten in ;C;"
,s can be seen from the basic hearty chart all if not all the indos in MFC are deri%ed from
this class in one form or another"
$-%&'
C'aint"C
The CPaint0C class is a de%ice+conte&t class deri%ed from C0C" /t performs a CWnd**1eginPaint
at construction time and CWnd**.ndPaint at destruction time" The CPaint0C ob)ect can only be
used hen responding to a WMGP,/BT message$ usually in your -nPaint message+handler
member function"
0ata Members
mGps Contains the P,/BT2T:4CT used to paint the client area"
mGhWnd The >WB0 to hich this CPaint0C ob)ect is attached"
CPaint0C is deri%ed as can be seen from C0C"
The C0C class defines a class of de%ice+conte&t ob)ects" The C0C ob)ect pro%ides member
functions for or!ing ith a de%ice conte&t$ such as a display or printer$ as ell as members for
or!ing ith a display conte&t associated ith the client area of a indo" ,ll draing is
accomplished through the member functions of a C0C ob)ect" The class pro%ides member
functions for de%ice+conte&t operations$ or!ing ith draing tools$ type+safe graphics de%ice
interface (@0/) ob)ect selection$ and or!ing ith colours and palettes"
/t also pro%ides member functions for getting and setting draing attributes$ mapping$ or!ing
ith the %ieport$ or!ing ith the indo e&tent$ con%erting co+ordinates$ or!ing ith
regions$ clipping$ draing lines$ and draing simple shapes$ ellipses$ and polygons" Member
functions are also pro%ided for draing te&t$ or!ing ith fonts$ using printer escapes$
scrolling$ and playing metafiles"
,lthough this encapsulation aids readability and conforms to the MFC Library structure on
reflection it can be seen that it offers %ery little impro%ement on the basic @0/ and Paint
options offered by the nati%e ,P/;s"
(.%&'
"ocument ()ie&s
4p to this point loo!ing at the classes that are the basis of an application MFC can still be
considered simply as rappers for C## around the basic ;C; ,P/ calls"
CWin,pp offers the control of the application"
9" 2tart+up
6" .&ecution
5" Termination
The concept of documents and %ies builds this into a frameor! for the application itself"
The C0ocument class pro%ides the basic functionality for user+defined document classes" ,
document represents the unit of data that the user typically opens ith the File -pen command
and sa%es ith the File 2a%e command C0ocument supports standard operations such as
creating a document$ loading it$ and sa%ing it" The frameor! manipulates documents using the
interface defined by C0ocument"
4sers interact ith a document through the C7ie ob)ect(s) associated ith it" , %ie renders
an image of the document in a frame indo and interprets user input as operations on the
document" A document can have multi%le vie&s associated &ith it.
0ocuments are part of the frameor!;s standard command routing and conse=uently recei%e
commands from standard user+interface components (such as the File 2a%e menu item)" ,
document recei%es commands forarded by the acti%e %ie"
When a document;s data is modified$ each of its %ies must reflect those modifications"
C0ocument pro%ides the 4pdate,ll7ies member function for you to notify the %ies of such
changes$ so the %ies can repaint themsel%es as necessary"
The frameor! also prompts the user to sa%e a modified file before closing it"
($%&'
CFrameWnd
The CFrameWnd class pro%ides the functionality of a Windos single document interface (20/)
o%erlapped or pop+up frame indo$ along ith members for managing the indo"
/t is ithin these CFrameWnd that e ill normally deri%e the C7ie onto our C0ocument data"
*S+, RES$*RCES WT- MFC .Menus/00
When an MFC application creates a indo ith a menu$ the message map macro that is used to
map WMGC-MM,B0 messages to handler functions is -BGC-MM,B0 (/0GIII$ -nIII)$ here
/0GIII is the menu item identifier in the resource script (":C file) and -nIII() is the handler
function that you ill need to rite to respond to the user ha%ing selected the menu item" For
e&ample$ if you had a menu item ",lpha" ith an /0 of /0MG,LP>, defined in the ":C file$ the
handler function (that you rite) ould normally be called -n,lpha()$ and ould$ of course$ be a
member function of your CMainWin class" /n this e&ample$ the message macro ould be*
-BGC-MM,B0 (/0MG,LP>,$-n,lpha)"
,s in ,P/ programming$ e can set up a "rc menu resource script file ith either a te&t editor
or %isually ith the 0e%eloper 2tudio menu editor" /f e do it %isually$ e;ll ha%e to edit both
the resulting resource"h and the "rc files to get rid of the e&tra "garbage" inserted by
0e%eloper 2tudioVs menu editor for use by its ,ppWi3ard (hich e;ll loo! at later)"
The resource"h file should only contain the Edefines for the menu item /0s" The programVs "rc
file should only ha%e the menu section and to Eincludes at
the top*
Einclude Waf&in"hK
Einclude "resource"h"
,ll the other stuff should be edited out of the to files" We should add the "cpp source file and
the "rc file to the pro)ect (as usual)$ and it should be built as in pre%ious e&amples"
((%&'
The M.B4 e&ample program++
(( MyWin,pp"h (,pplication Class 0eclaration
Einclude Waf&in"hK
class CMyWin,pp * public CWin,pp
F
public*
%irtual 1--L /nit/nstance()'
H'
(( MainFrame"h (Frame Windo Class 0eclaration
Einclude Waf&in"hK
class CMainFrame * public CFrameWnd
F
pri%ate*
public*
CMainFrame()'
af&Gmsg %oid -nPaint ()'
af&Gmsg %oid 0o-ption,9()'
af&Gmsg %oid 0o-ption,6()'
af&Gmsg %oid 0o-ption1(4/BT n/0)'
af&Gmsg %oid 0oClear()'

0.CL,:.GM.22,@.GM,P()
H'
(( Main"cpp (Main Program Creation)
Einclude "MyWin,pp"h" (Must)
CMyWin,pp My,pplication'
(( MainFrame"CPP (Frame Creation )
Einclude "MainFrame"h"
Einclude "resource"h" (( note

1.@/BGM.22,@.GM,P(CMainFrame$ CFrameWnd)
-BGWMGP,/BT()
-BGC-MM,B0 (/0G-PT/-B,G,9$ 0o-ption,9)
-BGC-MM,B0 (/0G-PT/-B,G,6$ 0o-ption,6)
-BGC-MM,B0G:,B@. (/0G-PT/-B1G19$
/0G-PT/-B1G15$
0o-ption1)
-BGC-MM,B0 (/0GCL.,:$ 0oClear)
.B0GM.22,@.GM,P()
()%&'
CMainFrame**CMainFrame()
F
Create ( B4LL$".&8Xa First Menu"$
W2G-7.:L,PP.0W/B0-W$
C:ect(8$8$6X8$688)$
B4LL$
M,C./BT:.2-4:C. (/0:GM.B49)
)'
H
%oid CMainFrame**-nPaint()
F
CPaint0C dc (this)'
H
%oid CMainFrame**0o-ption,9()
F
CClient0C dc(this)'
dc"Te&t-ut (98$98$"-ption ,9")'
H
%oid CMainFrame**0o-ption,6()
F
CClient0C dc(this)'
dc"Te&t-ut (98$98$"-ption ,6")'
H
%oid CMainFrame**0o-ption1(4/BT n/0)
F
CClient0C dc(this)'
sitch (n/0)
F
case /0G-PT/-B1G19*
dc"Te&t-ut (98$98$"-ption 19")'
brea!'
case /0G-PT/-B1G16*
dc"Te&t-ut (98$98$"-ption 16")'
brea!'
case /0G-PT/-B1G15*
dc"Te&t-ut (98$98$"-ption 15")'
brea!'
default*
brea!'
H
H
(*%&'
%oid CMainFrame**0oClear()
F
/n%alidate()'
H
(( MyWin,pp"cpp (,pplication Creation)
Einclude "MyWin,pp"h"
Einclude "MainFrame"h"
1--L CMyWin,pp**/nit/nstance()
F
CMainFrameI pFrame J ne CMainFrame'
mGpMainWnd J pFrame' (( a CWin,pp member %ariable
pFrame+K2hoWindo(2WG2>-W)'
pFrame+K4pdateWindo()' (( generates WMGP,/BT msg
return T:4.'
H
-utput* +
0/,L-@ 1-U.2 (:esources)
0ialog bo&es are %o%u% child &indo&s that Windo&s creates for special purpose input then
destroys immediately after use" Most often they are used for obtaining additional input from
the user beyond hat can be easily managed through a menu"
,ll aspects of a dialog bo& e&cept ho to carry out its tas!s are predefined" The application
supplies a template describing the contents$ style$ and layout of the dialog bo& and a dialog bo&
procedure to carry out its tas!s"
, dialog bo& almost alays contains se%eral child indo controls" 2i3e and placement of these
are specified in a dialog bo& template in the resource script file" ,s ith other resources the
design of the dialog bo& template can be done "%isually" using 0e%eloper 2tudio;s dialog bo&
editor or "manually" ith a te&t editor"
(&%&'
The programmer must pro%ide message+processing capability in the form of a callbac! function
li!e the main indo procedure" 1ut$ it;s really not the same' the Windo procedure for a
dialog bo& is inside Windos' it calls our dialog bo& function ith many of the messages it
recei%es" /t also interprets certain !eystro!es (tab$ etc")"
, good rule of thumb* use dialog bo&es for simple popup indos that ma!e use of normal
indo control items (buttons$ list bo&es$ etc")' use popup(child indos if e&tensi%e painting on
the indo is re=uired or the standard beha%ior of the indo is to be modified"
The main ad%antage of using dialog bo&es o%er using popup indos is their ease of construction
ith the dialog bo& editor"
There are three types of dialog bo&es* modal and modeless"
Modal++When the dialog bo& is %isible$ the user can;t sitch bac! to the parent indo"
(>oe%er e can usually change to another application") The user must e&plicitly end the dialog
bo& first (usually by clic!ing "-C" or "C,BC.L" buttons inside the dialog bo&)" Messages
resulting from user action ith the controls inside the dialog bo& go to the dialog bo&$ message+
processing function" Modal dialog bo&es are most common" For e&ample$ the ",bout" bo& that is
a%ailable ith most Windos applications is a modal dialog bo&"
LSystem Modal++a %ariety of modal dialog bo&" With these$ the user can;t e%en sitch to
another program hile the dialog bo& is acti%e"M
Modeless++The user can sitch beteen the dialog bo& and the parent indo" Theses are more
li!e popup indos and should be used hen the dialog bo& is to be displayed for some time
hile the user is doing stuff ith the parent indo" ,n .&ample is the dialog bo& resulting
from selecting "Find" or ":eplace" from the menu of many Windos applications" The resulting
dialog bo& stays around hile the user does things in the parent indo"
2teps in designing$ creating$ and using a modal dialog bo&++
9" 0etermine the child indo controls needed in the dialog bo&"
6" 0esign the dialog bo& template (easiest ith a dialog bo& editor)"
5" Write the message+processing function++e;ll see ho soon"
<" ,cti%ate the dialog bo& by calling 0ialog1o&()"
O" The resulting dialog bo& stays on the screen until .nd0ialog() is called
from inside dialog bo& function"
0ialog bo&es are of to types*
9" Modal +K , modal dialog bo& must be closed by the user before the application
continues
6" Modeless +K , modeless dialog bo& allos the user to display the dialog bo& and
return to another tas! ithout canceling or remo%ing the dialog bo&"
Modal and Modeless 0ialog 1o&es
?ou can use class C0ialog to manage to !inds of dialog bo&es*
(+%&'
Modal dialog bo&es$ hich re=uire the user to respond before continuing the program
Modeless dialog bo&es$ hich stay on the screen and are a%ailable for use at any time but
permit other user acti%ities
The resource editing and ClassWi3ard procedures for creating a dialog template are the same
for modal and modeless dialog bo&es"
Creating a dialog bo& for your program re=uires the folloing steps*
$# 4se the dialog editor to design the dialog bo& and create its dialog+template resource"
(# 4se ClassWi3ard to create a dialog class"
5" 4se ClassWi3ard to connect the dialog resourceVs controls to message handlers in the
dialog class"
<" 4se ClassWi3ard to add data members associated ith the dialog bo&Vs controls and to
specify dialog data e&change and dialog data %alidations for the controls
Modal dialog bo& creation* +
To create a modal dialog bo&$ construct an ob)ect on the stac! using the constructor for
your deri%ed dialog class and then call 0oModal to create the dialog indo and its
controls"
Call /nitModal/ndirect and 0oModal to create a modal dialog bo&"
The frameor! calls 4pdate0ata hen the user clic!s the -C button to close a modal
dialog bo&"
/f you de%elop a dialog bo& by hand$ you add the necessary member %ariables to the
deri%ed dialog+bo& class yourself$ and you add member functions to set or get these
%alues"
, modal dialog bo& closes automatically hen the user presses the -C or Cancel buttons
or hen your code calls the .nd0ialog member function"
Modal dialog bo&es are usually constructed on the frame and do not need
PostBc0estroy cleanup"
Modeless dialog creation* +
Call Create in the constructor of your dialog class"
?ou can also create a template in memory by using a 0L@T.MPL,T. data structure as
described in the Win56 20C documentation" ,fter you construct a C0ialog ob)ect$ call
Create/ndirect to create a modeless dialog bo&$
1oth the programmer and the frameor! call 0o0ata.&change indirectly through a call
to CWnd**4pdate0ata"
('%&'
?ou can call CWnd**4pdate0ata at any time during the e&ecution of a modal or modeless
dialog bo&"
When you implement a modeless dialog bo&$ alays o%erride the -nCancel member
function and call 0estroyWindo from ithin it" 0onVt call the base class
C0ialog**-nCancel$ because it calls .nd0ialog$ hich ill ma!e the dialog bo& in%isible but
ill not destroy it"
?ou should also o%erride PostBc0estroy for modeless dialog bo&es in order to delete
this$ since modeless dialog bo&es are usually allocated ith ne"
C0ialog Member Functions
Construction
C0ialog Constructs a C0ialog ob)ect"
/nitiali3ation
Create /nitiali3es the C0ialog ob)ect" Creates a modeless dialog bo& and attaches it
to the C0ialog ob)ect"
Create/ndirect Creates a modeless dialog bo& from a dialog+bo& template in memory (not
resource+based)"
/nitModal/ndirect Creates a modal dialog bo& from a dialog+bo& template in memory (not
resource+based)" The parameters are stored until the function 0oModal is
called"
-perations
0oModal Calls a modal dialog bo& and returns hen done"
Map0ialog:ect Con%erts the dialog+bo& units of a rectangle to screen units"
Be&t0lgCtrl Mo%es the focus to the ne&t dialog+bo& control in the dialog bo&"
Pre%0lgCtrl Mo%es the focus to the pre%ious dialog+bo& control in the dialog bo&"
@oto0lgCtrl Mo%es the focus to a specified dialog+bo& control in the dialog bo&"
.&ample Program 0ialog 1o& Creation
-eader Files 10
(( MyWin,pp"h
(,%&'
Einclude Waf&in"hK
class CMyWin,pp * public CWin,pp
F
public*
%irtual 1--L /nit/nstance()'
H'
(( MainFrame"h
Einclude Waf&in"hK
class CMainFrame * public CFrameWnd
F
pri%ate*
C2tring mBame'
int m,ge'
public*
CMainFrame()'
af&Gmsg %oid 2ho0ialog()'
0.CL,:.GM.22,@.GM,P()
H'
(( My0ialog"h* interface for the CMy0ialog class"
Einclude Waf&in"hK
Einclude "resource"h"
class CMy0ialog * public C0ialog
F
public* (( Correspondence 7ariables Controls
C2tring name' (( /0CGB,M.
int age' (( /0CG,@.
CMy0ialog(CWndI pParentWnd)'
%irtual YCMy0ialog()'
%irtual 1--L -n/nit0ialog()'
%irtual %oid -n-C()'
H'
Source Files1 0
(( Main"cpp
(-%&'
Einclude "MyWin,pp"h"
CMyWin,pp My,pplication'
(( MainFrame"CPP
Einclude "MainFrame"h"
Einclude "My0ialog"h" (( note

1.@/BGM.22,@.GM,P(CMainFrame$ CFrameWnd)
-BGC-MM,B0 (/0G2>-W0/,L-@$ 2ho0ialog)
.B0GM.22,@.GM,P()
CMainFrame**CMainFrame()
F
Create ( B4LL$" 2imple 0ialog"$
W2G-7.:L,PP.0W/B0-W$
C:ect(8$8$588$688)$
B4LL$
M,C./BT:.2-4:C. (/0:GM.B49)
)'
mBame J "2ar%esh"'
m,ge J S'
H
%oid CMainFrame**2ho0ialog()
F
CClient0C dc (this)'
CMy0ialog 0lg(this)' (( .&G2tep 9* Create the dialog ob)ect
0lg"name J mBame' (( .&G2tep 5* /nit dialog %ariables
0lg"age J m,ge'
(( .&G2tep <* /n%o!e the dialog
if (0lg"0oModal() JJ /0-C)
F (( .&G2tep Z* :eturn from dialog
mBame J 0lg"name' (( .&G2tep X* :etrie%e %alues
m,ge J 0lg"age' (( from dialog %ariables
C2tring s'
s"Format ("Bame* [s ,ge* [d"$ mBame$ m,ge)'
dc"Te&t-ut (98$98$s)'
H
else
dc"Te&t-ut (98$98$"?ou press C,BC.L")'
H
(( My0ialog"cpp
Einclude "My0ialog"h"
(( B- Message Map entries"
(( C0ialog has entries for the msg handlers
).%&'
(( -n/nit0ialog() and -n-C()
CMy0ialog**CMy0ialog(CWndI pParentWnd)
* C0ialog (/00G0/,L-@9$ pParentWnd) (( .&G2tep 6*
F H (( 0ialog bo&
(( constructed
CMy0ialog**YCMy0ialog() F H
1--L CMy0ialog**-n/nit0ialog() (( .&G2tep O*
F (( Copy %alues
2et0lg/temTe&t (/0CGB,M.$ name)'(( from dialog
2et0lg/tem/nt (/0CG,@.$ age)' (( %ariables
return T:4.' (( into controls
H
%oid CMy0ialog**-n-C() (( .&G2tep S*
F (( Copy %alues
@et0lg/temTe&t(/0CGB,M.$name)' (( from controls
age J @et0lg/tem/nt (/0CG,@.)' (( to dialog
(( %ariables
C0ialog**-n-C()' (( W+ a must
H
(( MyWin,pp"cpp
Einclude "MyWin,pp"h"
Einclude "MainFrame"h"
1--L CMyWin,pp**/nit/nstance()
F
CMainFrameI pFrame J ne CMainFrame'
mGpMainWnd J pFrame' (( a CWin,pp member %ariable
pFrame+K2hoWindo(2WG2>-W)'
pFrame+K4pdateWindo()' (( generates WMGP,/BT msg
return T:4.'
H
Cstring *+
>eader File ,f&"h
)$%&'
C2tring does not ha%e a base class"
, C2tring ob)ect consists of a %ariable+length se=uence of characters"
C2tring pro%ides functions and operators using a synta& similar to that of 1asic"
Concatenation and comparison operators$ together ith simplified memory
management$ a!e C2tring ob)ects easier to use than ordinary character arrays"
C2tring assists you in conser%ing memory space by alloing to strings sharing
the same %alue also to share the same buffer space"
The C2tring class pro%ides support for manipulating strings
The class also pro%ides constructors and operators for constructing$ assigning$
and comparing C2trings and standard C## string data types
C2tring ob)ects also ha%e the folloing characteristics*
C2tring ob)ects can gro as a result of concatenation operations"
C2tring ob)ects follo \%alue semantics"] Thin! of a C2tring ob)ect as an actual string$
not as a pointer to a string"
?ou can freely substitute C2tring ob)ects for const charI and LPCT2T: function
arguments"
, con%ersion operator gi%es direct access to the stringVs characters as a read+only array
of characters (a C+style string)"
Tip Where possible$ allocate C2tring ob)ects on the frame rather than on the heap" This
sa%es memory and simplifies parameter passing"
C2tring Member Functions
Construction
C2tring Constructs C2tring ob)ects in %arious ays"
The 2tring as an ,rray
@etLength :eturns the number of characters in a
C2tring ob)ect"
/s.mpty Tests hether a C2tring ob)ect contains no
characters"
@et,t :eturns the character at a gi%en position"
Cedit *+
The C.dit class encapsulates the functionality of a Windos edit control$ hich is a
rectangular child indo in hich a user can enter te&t"
>eader File ,f&in"h
)(%&'
The C.dit class pro%ides the functionality of a Windos edit control"
,n edit control is a rectangular child indo in hich the user can enter te&t"
?ou can create an edit control either from a dialog template or directly in your
code" /n both cases$ first call the constructor C.dit to construct the C.dit
ob)ect$ then call the Create member function to create the Windos edit control
and attach it to the C.dit ob)ect"
C.dit Member Functions
Clist7ie (or) Clist *+
The CList7ie class simplifies use of the list control and of CListCtrl$ the class that
encapsulates list+control functionality$ ith MFC;s document+%ie architecture"
>eader file* ,f&c%ie"h
Construction
C.dit Constructs a C.dit control ob)ect"
Create Creates the Windos edit control and
attaches it to the C.dit ob)ect"
))%&'
CList7ie Class Members
Construction
CList7ie Constructs a CList7ie ob)ect"
Cmenu *+
The CMenu class is an encapsulation of the Windos >M.B4"
/t pro%ides member functions for creating$ trac!ing$ updating$ and destroying a
menu"
Create a CMenu ob)ect on the stac! frame as a local$ then call CMenuVs member
functions to manipulate the ne menu as needed"
Be&t$ call CWnd**2etMenu to set the menu to a indo$ folloed immediately by a
call to the CMenu ob)ectVs 0etach member function"
The CWnd**2etMenu member function sets the indoVs menu to the ne menu$
causes the indo to be redran to reflect the menu change$ and also passes
onership of the menu to the indo"
The call to 0etach detaches the >M.B4 from the CMenu ob)ect$ so that hen
the local CMenu %ariable passes out of scope$ the CMenu ob)ect destructor does
not attempt to destroy a menu it no longer ons"
The menu itself is automatically destroyed hen the indo is destroyed"
CMenu**CMenu
The menu is not created until you call one of the create or load member functions of CMenu*
CreateMenu
CreatePopupMenu
LoadMenu
LoadMenu/ndirect
,ttach
CMenu Class Members
0ata Members
mGhMenu 2pecifies the handle to the Windos menu attached to the CMenu
)*%&'
ob)ect"
Construction
CMenu Constructs a CMenu ob)ect"
Cin,pp *
The CWin,pp class is the base class from hich you deri%e a Windos application
ob)ect"
,n application ob)ect pro%ides member functions for initiali3ing your application
(and each instance of it) and for running the application"
.ach application that uses the Microsoft Foundation classes can only contain one
ob)ect deri%ed from CWin,pp"
This ob)ect is constructed hen other C## global ob)ects are constructed and is
already a%ailable hen Windos calls the WinMain function$ hich is supplied by
the Microsoft Foundation Class Library"
0eclare your deri%ed CWin,pp ob)ect at the global le%el"
When you deri%e an application class from CWin,pp$ o%erride the /nit/nstance
member function to create your applicationVs main indo ob)ect"
/n addition to the CWin,pp member functions$ the Microsoft Foundation Class Library pro%ides
the folloing global functions to access your
CWin,pp ob)ect and other global information *
,f&@et,pp -btains a pointer to the CWin,pp ob)ect"
,f&@et/nstance>andle -btains a handle to the current application instance"
,f&@et:esource>andle -btains a handle to the applicationVs resources"
,f&@et,ppBame -btains a pointer to a string containing the applicationVs name"
,lternately$ if you ha%e a pointer to the CWin,pp ob)ect$ use mGps3.&eBame to get the
applicationVs name"
:esource .ditors
)&%&'
The :esource editors share techni=ues and interfaces to create and modify application
resources =uic!ly and easily" ?ou can use the :esource editors to create ne resources$ modify
e&isting resources$ copy e&isting resources$ and delete old resources" The :esource editors are
functionally consistent for ease of use"
,ccelerator .ditor
,n accelerator table is a Windos resource that contains a list of accelerator !eys (also !non
as shortcut !eys) and the command identifiers that are associated ith them" , program can
ha%e more than one accelerator table"
Bormally$ accelerators are used as !eyboard shortcuts for program commands that are also
a%ailable on a menu or toolbar" >oe%er$ you can use the accelerator table to define !ey
combinations for commands that donVt ha%e a user+interface ob)ect associated ith them" ?ou
can use Class Wi3ard to hoo! accelerator !ey commands to code"
With the ,ccelerator editor$ you can*
,dd$ delete$ change$ and brose the accelerator !ey assignments in your pro)ect"
7ie and change the resource identifier associated ith each entry in the accelerator
table" The identifier is used to reference each accelerator table entry in program code"
,ssociate an accelerator !ey ith a menu item"
)+%&'
Find one or more accelerator !eys in the accelerator table$ and use regular e&pressions
ith the Find command to locate an accelerator !ey that matches a pattern"
2elect multiple accelerator !eys and change their properties at one time"
To associate a menu item ith an accelerator !ey
9" /n the menu editor$ select the menu item you ant" From the 7ie menu$ choose
Properties or double+clic! the item"
6" /n the Caption bo&$ add the name of the accelerator !ey to the menu caption*
Folloing the menu caption$ type the escape se=uence for a tab (^t)$ so that all
the menuVs accelerator !eys are left aligned"
Type the name of the modifier !ey (CT:L$ ,LT$ or 2>/FT) folloed by a plus sign
(#) and the name$ letter$ or symbol of the additional !ey"
For e&ample$ to assign CT:L#- to the -pen command on the File menu$ you modify the
menu itemVs caption so that it loo!s li!e this*
-pen^tCtrl#-
The menu item in the Menu editor is updated to reflect the ne caption as you type it"
5" Create the accelerator+table entry in the accelerator editor and assign it the same
identifier as the menu item" 4se a !ey combination that you thin! ill be easy to
remember"
/cons and Cursors
/cons and cursors are li!e images$ and you edit them in the same ays" >oe%er$ icons and
cursors ha%e attributes that distinguish them from images" For e&ample$ each icon or cursor
resource can contain multiple images for different display de%ices" /n addition$ a cursor has a
\hot spot]* the location Windos uses to trac! its position"
When you create a ne icon or cursor$ the @raphics editor first creates an image for 7@," The
image is initially filled ith the \screen] (transparent) color" /f the image is a cursor$ the hot
spot is initially the upper+left corner (coordinates 8$8)"1y default$ the graphics editor supports
the creation of images for the de%ices shon in the folloing table"
-%er%ie* 2tring .ditor
, string table is a Windos resource that contains a list of /0s$ %alues$ and captions for all the
strings of your application" For e&ample$ the status+bar prompts are located in the string table"
,n application can ha%e only one string table"
2tring tables ma!e it easy to locali3e your application into different languages" /f all strings are
in a string table$ you can locali3e the application by translating the strings (and other
resources) ithout changing source code"
With the 2tring editor$ you can edit a programVs string table resource" /n a string table$ strings
are grouped into segments$ or bloc!s$ of 9S strings each" The segment a string belongs to is
determined by the %alue of its identifier' for e&ample$ strings ith identifiers of 8 to 9O are in
one segment$ strings ith identifiers of 9S to 59 are in a second segment$ and so on" Thus$ to
mo%e a string from one segment to another you need to change its identifier"
)'%&'
/ndi%idual string segments are loaded on demand in order to conser%e memory" For this reason$
programmers usually try to group strings into logical groupings of 9S or less and then use each
group or segment only hen it is needed"
?ou can search for one or more strings in the string table$ and use regular e&pressions ith the
Find command to locate all instances of strings that match a pattern" ,lso$ you can select
multiple strings and change their properties at one time"
-%er%ie* 7ersion /nformation .ditor
7ersion information consists of company and product identification$ a product release number$
and copyright and trademar! notification" The 7ersion /nformation editor is a tool for creating
and maintaining this data" ,lthough the %ersion information resource is not re=uired by an
application$ it is a useful place to collect this information that identifies the application"
, single %ersion information resource can contain multiple string bloc!s$ each representing a
different language or character set" ,ll you need to do is define the character sets and
languages that are specific to your product"
With the 7ersion /nformation editor$ you can add or delete string bloc!s$ search for %alues$ and
modify indi%idual string %alues"
),%&'
M.22,@. M,PP/B@
, message map is an ob)ect oriented alternati%e to sitch+case message handling statement
found in the indo procedures of 20C programs" The Cin,pp**:un() method fetches
messages from the message =ueue and routes then to the application indo here it has to
sent" @enerally most of the messages are routed to the mainframe indo of an application"
Windo ob)ects directly handle message that recei%e indo" The command message that
comes from an applicationVs mainframe indo tra%els through the command target hierarchy
until a match is found in a message handler$ after hich the message handler is called" .ach and
e%ery ob)ect ons a message map capable of recei%ing messages or commands" The message map
associates a message or command ith a specific message handler method"
, message map has both declaration and implementation parts" , message map is declared by
)ust using the 0.CL,:.GM.22,@.M,P macro at the end of class declaration" 2ay$ for
e&ample e ha%e a class Cclass and ant to associate this class ith a message map" We must
declare first this message map in the class declaration using macro
0.CL,:.GM.22,@.GM,P*
Class Cclass *public Cob)ect
F
)-%&'
pri%ate*
static const ,FUGM2@M,PG.BT:?Gmessage.ntriesLM'
protected*
static ,FUG0,T, const ,FUGM2@M,P messagemap'
%irtual condt ,FUGM2@M,PI @etMessageMap() const'
H
Coming to the implementation of the message maps$ message handler methods can be located
anyhere in a hierarchy of deri%ed classes"MFC uses the message map architecture to search
all inherited classes until it finds the handler fir a gi%en message" , message map uses the class
information pro%ided in the 1.@/BGM.22,@.GM,P macro to search bac! through the class
hierarchy from the current class and in the base class$ all the ay up the MFC class tree until it
gets to Ccmdtarget" Message maps are used to designate the functions that ill handle %arious
messages for a particular class" Message map contains one or more macros that specify the
functions handling the messages"
The 1.@/BGM.22,@.GM,P macro is used ith in the class implementation folloed by the
.B0GM.22,@.GM,P macro" The 1.@/BGM.22,@.GM,P macro ta!es to parameters* the
current class and its immediate ancestor class"
1.@/BGM.22,@.GM,P(Cclass$Cob)ect)
((______
((,dd message map entries here
((
.B0GM.22,@.G,MP()M
,t the end of the declaration of a class the 0.CL,:.GM.22@.G,MP macro is used"This
represents the presence of message map entries after the class$the handlers `` ha%e been
rittern as member functions of the class"T- being ith the definition of message maps$the
1.@/BGM.22,@.GM,P amcro is used"The class name of the parent class abd the name of the
deri%ed class are passed as parameters to the mactro"The macro entries for each message
handler function should follo the 1.@/BGM.22,@.G.BT:?"
The end of defining a message map is mar!ed by the .B0GM.22,@.GM,P macro" This
indicates to MFC that there are no message map entries for the particular class"
,lso apart from the defined macros there is an -BGC-MM,B0 macro hich is usually inserted
in a message map by the class i3ard or manually"/t specifies the function that ill handle a
coomand message form a command userGinterface ob)ect$such as a menu item or toolbar
button"-n the commandGtarget ob)ect rece%ing a indo WMGC-MM,B0
*.%&'
M.22,@. ith the specified /0$-BGC-MM,B0 calls for the member function defined in the
respecti%e class to handle the message"
Message Map .ntries ,nd Message >andler methods
The general synta& used for a message map entry is gi%en here"

/n the abo%e synta&$Messagename is the message to the handler$/0 is the idenifier of the
sender of the message and ClassMethod is the name of the class method that ill handle the
message"Many predefined MFC message map entry macros and corresponding message handler
method prototypes for std indos messages"These are bro!en into the folloing
Categories of message map entries*
Command Message handlers
Child indo notification message handlers
Windo message handlers
Command Message handlers*
These message map entries handle WMGC-MM,B0 message generated by a user$by ma!ing a
menu selection or by using a !eyboard accelerator"The WMGC-MM,B0 message is handled for
%arious application components ith the -BGC-MM,B0 message map entries"Control identifier
and a corresponding class method are the to parameters passed to this message map entry to
handle the message"
-BGC-MM,B0(id$classmethod)
, corresponding message handler mehtos is placed int eh class declaration"
Child indo Botification Message >andlers *
These message handlers ta!e care of notification messages from child indo" There are
fi%e types of child indo notification messages'
1utton handlers
.dit control handlers
@eneric control handlers
List bo& handlers
Combo bo& handlers
@eneric Control Botification >andlers *
*$%&'
ON_MessageName(ID,ClassMethod)
Consider an e&ample of a generic message map entry*
-BGC-BT:-L (BotifyCode$ /0 $ ClassMethod )
/n the abo%e$ illustrated synta&$ BotifyCode is the message or command to handle$ /d is the
control identifier and ClassMethod is the message handler method defined for the class" ,
corresponding message handler method is placed in the class declaration using the synta& gi%en"
af&Gmsg %oid ClassMethod()'
1utton Control Botification >andlers *
This type of notification message handlers are defined by MF0C for button controls"
The general form of these handlers is shon here *
-BG1BGI.7.BTI(1utton/0$ ClassMethod)
/n the abo%e illustrated synta&$ 1utton/0 represents the control identifier of the button$ and
the ClassMethod represents the message handler method for the class -BG1BGI.7.BTI
represents any of the folloing predefined 1BGImessage macros *
-BG1BGCL/CC.0
-BG1BG0/2,1L.
-BG1BG0-41L.CL/CC.0
-BG1B+>/L/T.
-BG1BGP,/BT
-BG1BG4B>/L/T.
The corresponding message handler method in the class declaration loo!s as gi%en belo$ here
Classmethod indicates the actual message handler name* ,f&Gmsg %oid ClassMethod()'
Messages
The message loop in the :un member function of class CWin,pp retrie%es =ueued messages
generated by %arious e%ents" For e&ample$ hen the user clic!s the mouse$ Windos sends
se%eral mouse+related messages$ such as WMGL14TT-B0-WB hen the left mouse button is
pressed and WMGL14TT-B4P hen the left mouse button is released" The frameor!Vs
implementation of the application message loop dispatches the message to the appropriate
indo"
What !inds of messages do you rite handlers for? There are three main categories*
9" Windos messages
*(%&'
This includes primarily those messages beginning ith the WMG prefi&$ e&cept for
WMGC-MM,B0" Windos and %ies handle Windos messages" These messages often
ha%e parameters that are used in determining ho to handle the message"
6" Control notifications
This includes WMGC-MM,B0 notification messages from controls and other child
indos to their parent indos" For e&ample$ an edit control sends its parent a
WMGC-MM,B0 message containing the .BGC>,B@. control+notification code hen
the user has ta!en an action that may ha%e altered te&t in the edit control" The indoVs
handler for the message responds to the notification message in some appropriate ay$
such as retrie%ing the te&t in the control"
The frameor! routes control+notification messages li!e other WMG messages" -ne
e&ception$ hoe%er$ is the 1BGCL/CC.0 control+notification message sent by buttons
hen the user clic!s them" This message is treated specially as a command message and
routed li!e other commands"
5" Command messages
This includes WMGC-MM,B0 notification messages from user+interface ob)ects*
menus$ toolbar buttons$ and accelerator !eys" The frameor! processes commands
differently from other messages$ and they can be handled by more !inds of ob)ects$
Message 2ending and :ecei%ing
Consider the sending part of the process and ho the frameor! responds" Most messages
result from user interaction ith the program" Commands are generated by mouse clic!s in menu
items or toolbar buttons or by accelerator !eystro!es" The user also generates Windos
messages by$ for e&ample$ mo%ing or resi3ing a indo" -ther Windos messages are sent hen
e%ents such as program startup or termination occur$ as indos get or lose the focus$ and so
on" Control+notification messages are generated by mouse clic!s or other user interactions ith
a control$ such as a button or list+bo& control in a dialog bo&"
The :un member function of class CWin,pp retrie%es messages and dispatches them to the
appropriate indo" Most command messages are sent to the main frame indo of the
application" The WindoProc predefined by the class library gets the messages and routes them
differently$ depending on the category of message recei%ed"
>andlers for Message+Map :anges
This article e&plains ho to map a range of messages to a single message handler function
(instead of mapping one message to only one function)"
There are times hen you need to process more than one message or control notification in
e&actly the same ay" ,t such times$ you might ish to map all of the messages to a single
handler function" Message+map ranges allo you to do this for a contiguous range of messages*
?ou can map ranges of command /0s to*
, command handler function"
, command update handler function"
*)%&'
?ou can map control+notification messages for a range of control /0s to a message
handler function"
Topics co%ered in this article include*
Writing the message+map entry
0eclaring the handler function
.&ample for a range of command /0s
.&ample for a range of control /0s
/mportant ClassWi3ard does not support message+map ranges$ so you must rite the message+
map entries and handler function declarations yourself"
Writing the Message+Map .ntry
/n the "CPP file$ add your message+map entry$ as shon in the folloing e&ample*
"""
1.@/BGM.22,@.GM,P(CMy,pp$ CWin,pp)
((FF,FUGM2@GM,P(CMy,pp)
"""
((HH,FUGM2@GM,P
-BGC-MM,B0G:,B@.(/0GM?CM0G-B.$ /0GM?CM0GT.B$
-n0o2omething)
.B0GM.22,@.GM,P( )
"""
The message+map entry consists of the folloing items*
The message+map range macro*
-BGC-MM,B0G:,B@.
-BG4P0,T.GC-MM,B0G4/G:,B@.
-BGC-BT:-LG:,B@.
Parameters to the macro*
The first to macros ta!e three parameters*
The command /0 that starts the range
The command /0 that ends the range
The name of the message handler function
The range of command /0s must be contiguous"
The third macro$ -BGC-BT:-LG:,B@.$ ta!es an additional first parameter* a control+
notification message$ such as .BGC>,B@."
0eclaring the >andler Function
**%&'
/n the "> file$ add your handler function declaration outside the //{{AFX_MSG comment brac!ets"
The folloing code shos ho this might loo!$ as shon in the ne&t+to+last line belo*
(( @enerated message+map functions
protected*
((FF,FUGM2@(CMy,pp)
"""
((HH,FUGM2@
af&Gmsg %oid -n0o2omething( 4/BT
n/0 )'
0.CL,:.GM.22,@.GM,P()
>andler functions for single commands normally ta!e no parameters" With the e&ception of
update handler functions$ handler functions for message+map ranges re=uire an e&tra
parameter$ n/0$ of type 4/BT" This parameter is the first parameter" The e&tra parameter
accommodates the e&tra command /0 needed to specify hich command the user actually
chose"
.&ample for a :ange of Command /0s
When might you use ranges? -ne e&ample is in handling commands li!e the aoom command in the
MFC sample >/.:27:" This command 3ooms the %ie$ scaling it beteen 6O[ and 588[ of its
normal si3e" >/.:27:Vs %ie class uses a range to handle the aoom commands ith a message+
map entry resembling this*
-BGC-MM,B0G:,B@. (/0G7/.WGa--M6O$ /0G7/.WGa--M588$ -naoom)
When you rite the message+map entry$ you specify*
To command /0s$ beginning and ending a contiguous range"
>ere they are ID_VIEW_ZOOM25 and ID_VIEW_ZOOM3"
The name of the handler function for the commands"
,pplication frameor!
-r frameor!" , group of C## classes in the Microsoft Foundation Class Library that pro%ides
the essential components of an application for Windos" The application frameor! defines the
s!eleton$ or frameor!$ of an application and supplies standard user+interface implementations
that can be placed onto the s!eleton" 2ee also class library"
,pplication programming interface
, set of routines that an application uses to re=uest and carry out loer+le%el ser%ices
performed by a computerVs operating system" For computers running a graphical user interface$
an ,P/ manages an application;s indos$ icons$ menus$ and dialog bo&es"
*&%&'
,pplication ob)ect
The single instance of the application class" The application ob)ect controls documents$ %ies$
frame indos$ and templates$ and specifies application beha%ior such as initiali3ation and
cleanup for e%ery instance of the application"
,pplication =ueue
/n Microsoft Windos$ a repository for messages aaiting processing by a particular
application" ,s Windos remo%es messages from its system message =ueue$ it dispatches the
messages that contain application input to the rele%ant application =ueue" 2ee also message loop$
message =ueue"
,rchi%e
9" ,n ob)ect$ deri%ed from the MFC class C,rchi%e$ that pro%ides a type+safe buffering
mechanism for riting or reading seriali3able ob)ects to or from a CFile ob)ect Q a dis!
file or a memory file (perhaps representing the Clipboard)" , gi%en C,rchi%e ob)ect
either stores (rites$ seriali3es) data or loads (reads$ deseriali3es) data$ but ne%er both"
2ee also seriali3ation"
6" /n general$ a stored bac!up copy of data or a program$ or the act of storing a bac!up
copy of data or a program
,TL
, set of compact$ template+based C## classes that simplify the programming of Component
-b)ect Model ob)ects" ,TL pro%ides the mechanism to use and create C-M ob)ects"
1ase priority
/n multitas!ing$ the priority le%el that pro%ides the basis for calculating a thread;s dynamic
priority for CP4 time" , thread inherits its base priority from the process in hich the thread
as created" The scheduler$ hich determines the order in hich threads should e&ecute$ can
temporarily boost the priority of a thread$ but it cannot reduce the priority belo this base
priority"
1itmap
9" -r pi&el image$ pi&el map" ,n array of bits that contains data describing the colors found
in a rectangular region on the screen (or the rectangular region found on a page of
printed paper)"
6" -r bit image" , se=uential collection of bits that represents$ in memory$ an image to be
displayed on the screen or printed" 2ee also bitmap file"
1itmap file
, file that contains a collection of structures that specify or contain the folloing
elements*
*+%&'
, header that describes the resolution of the de%ice on hich the rectangle of pi&els
as created$ the dimensions of the rectangle$ the si3e of the array of bits$ and so on"
, logical palette"
,n array of bits that defines the relationship beteen pi&els in the bitmapped image and
entries in the logical palette"
1itmap files usually ha%e a "1MP filename e&tension" 2ee also bitmap$ de%ice+independent bitmap
file"
1rose buttons
9" /n Windos >elp$ a pair of buttons used to brose bac!ards and forards through a
se=uence of >elp topics" , brose se=uence typically consists of to or more related
topics that are intended to be read se=uentially"
6" /n dialog bo&es$ buttons used to %ie a list of netor! ser%ers$ directories$ files$ etc"
1rush
, graphics ob)ect used to paint the interior of shapes and paths" , brush describes an X+ by X+
pi&el bitmap" 2ee also logical brush$ physical brush"
1uffer
9" (noun) ,n intermediate repository of data Q a reser%ed portion of memory in hich data
is temporarily held pending an opportunity to complete its transfer to or from a storage
de%ice or another location in memory"
6" (%erb) To store or collect in a buffer"
button control
, graphical control that enables a user to pro%ide input to an application" Windos pro%ides fi%e
!inds of button controls* pushbuttons$ chec! bo&es$ radio buttons$ group bo&es$ and oner+dra
buttons"
1yte
, unit of information consisting of X bits" , byte$ or "binary term$" is the smallest collection of
bits that can be accessed directly"
byte code
Machine+independent code generated by the Da%a compiler and e&ecuted by the Da%a
interpreter or compiled at the last minute by a D/T compiler"
Calling con%ention
, con%ention that determines the order in hich arguments passed to functions are pushed on
the stac! (the calling se=uence)$ hether the calling or called function remo%es the arguments
*'%&'
from the stac!$ and the name+decorating con%ention the compiler uses to identify indi%idual
functions" 2ee also C calling con%ention$ calling se=uence"
Calling se=uence
0etermines the order in hich parameters are pushed onto the stac! during a function call and
hich code bloc! is responsible for the stac! pointer" Typically$ the C compiler generates code
that pushes parameters on the stac! from right to left$ beginning ith the last parameter" 2ee
also calling con%ention
Child indo
, indo that has the W2GC>/L0 or W2GC>/L0W/B0-W style and is confined to the client
area of its parent indo$ hich initiates and defines the child indo" Typically$ an application
uses child indos to di%ide the client area of a parent indo into functional areas" 2ee also
child control$ sibling indo"
Class library
, set of related C## classes that can be used in an application$ either as originally defined or as
the source for other deri%ed classes" The Microsoft Foundation Class Library included in 7isual
C## is an e&ample of a class library that defines a frameor! for integrating the user interface
of an application for Windos ith the rest of the application"
Class Wi3ard file
A !ile t"at #lassWi$a%& 'ene%ates( containin' in!o%)ation nee&e& to e&it existin' classes o%
a&& ne* classes to a p%o+ect, #lassWi$a%& also -ses t"e #lassWi$a%& !ile to sto%e
in!o%)ation nee&e& to c%eate an& e&it )essa'e )aps an& &ialo' &ata )aps( an& to c%eate
p%otot.pe )e)/e% !-nctions, #lassWi$a%& !iles "a0e a ,#1W !ilena)e extension,
Client area
-r client rectangle" The portion of a indo here the application displays output such as te&t
or graphics
Command identifier
-r command /0" /n MFC$ an identifier that associates a command message ith the user+
interface ob)ect (such as a menu item$ toolbar button$ or accelerator !ey) that generated the
command" Typically$ command /0s are named for the functionality of the user+interface ob)ect
they are assigned to" For e&ample$ a Clear ,ll item in the .dit menu might be assigned an /0
such as /0G.0/TGCL.,:G,LL"
Command message
9" /n Windos$ a notification message from a user+interface ob)ect$ such as a menu$
toolbar button$ or accelerator !ey" The frameor! processes command messages
differently from other messages and such messages can be handled by a ider %ariety of
*,%&'
ob)ect Q documents$ document templates$ and the application ob)ect itself$ in addition
to indos and %ies"
6" /n Media Control /nterface (MC/)$ a symbolic constant that represents a uni=ue
command for an MC/ de%ice" Command messages ha%e associated data structures that
pro%ide information a de%ice re=uires to carry out a re=uest
Compact e&ecutable file
,n e&ecutable binary (program) file hose code is limited to a single S<+!ilobyte segment"
Compact e&ecutable files usually ha%e a "C-M filename e&tension and are often used for utility
programs and short routines" 2ee also e&ecutable file"
Compiled resource file
-r binary resource file" , binary file that contains a Windos+based application;s resource
data and is created by the resource compiler from the resource+definition (":C) file" Compiled
resource files usually ha%e a ":.2 filename e&tension" 2ee also Macintosh binary resource file$
resource compiler"
Console
,n interface that pro%ides input and output to character+mode applications" This processor+
independent mechanism ma!es it easy to port e&isting character+mode applications or to create
ne character+mode tools and applications"
Console application
9" , character+mode application that uses a console indo for its input and output" /f
necessary$ the operating system ill create a ne console indo$ hich e&ists until the
application terminates"
6" More generally$ a program that runs from the operating system;s command line$ in
character+mode$ rather than from a graphical user interface"
Conte&t identifier (/0)
-r conte&t reference" , uni=ue number or string that corresponds to a particular ob)ect in the
application Q for e&ample$ to a menu command$ form$ control$ or screen region" Conte&t /0s are
used to create lin!s beteen the application and the corresponding >elp topics"
Conte&t number
The number used to identify a Windos >elp topic" /f conte&t numbers are not e&plicitly
assigned to topics$ the >elp compiler generates default %alues by con%erting topic strings into
conte&t numbers" The LM,PM section of a >elp pro)ect (">PD) file associates a conte&t string
and a conte&t number" 2ee also conte&t string"
*-%&'
Conte&t string
, uni=ue character string formatted as hidden te&t in a rich+te&t format (":TF) file" Conte&t
strings lin! "hot spots" to target topics" The LM,PM section of a >elp pro)ect (">PD) file
associates a conte&t string and a conte&t number" 2ee also conte&t number
Control identifier (/0)
, 9S+bit %alue that an application uses to uni=uely identify a child control" This /0 is used in
notification messages to the parent indo hen e%ents$ such as input from the user$ occur in
the control"
Custom control
, special+format dynamic+lin! library (0LL) or ob)ect file that adds features and functionality
to a Windos+based application user interface" , custom control can be a %ariation on an
e&isting Windos dialog+bo& control (for e&ample$ a te&t bo& suitable for use ith a pen and
digiti3ing tablet) or an entirely ne category of control" 2ee also ,cti%eU control"
0ata ,ccess -b)ects (0,-)
, high+le%el set of ob)ects that insulate de%elopers from the physical details of reading and
riting records" /n a database application$ for e&ample$ these ob)ects include databases$ table
definitions$ =uery definitions$ fields$ inde&es$ etc"
0ata handle
/n Microsoft Windos$ a 56+bit %alue used to pro%ide access to data in a dynamic data e&change
(00.) ob)ect"
00.
, form of interprocess communications that uses shared memory to e&change data beteen
applications" 00. can be used for one+time data transfers and for ongoing e&changes by
applications that send updates to one another as ne data becomes a%ailable" 2ee also
client(ser%er$ -L. ,utomation"
00L
-r database design language$ data design language" , language$ usually a part of a database
management system$ that defines all attributes and properties of a database$ especially record
layouts$ field definitions$ !ey fields (and$ sometimes$ !eying methodology)$ file locations$ and
storage strategy"
0efault message processing
Message processing carried out by a default indo procedure on any indo messages for
hich there is not an e&plicit procedure defined in the application" /n applications based on the
Microsoft Foundation Class Library$ 0efWindoProc is the default indo procedure"
&.%&'
0efault indo procedure
, system+defined function that defines certain fundamental beha%ior shared by all indos" ,
default indo procedure pro%ides default processing for nonclientNarea messages$ system
commands$ system !eystro!es$ and other messages that the application+defined indo
procedure does not specifically handle" 2ee also indo procedure"
0escendant indo
, child indo that is deri%ed from a parent indo" , child indo has only one parent indo$
but a parent can ha%e any number of child indos" .ach child indo$ in turn$ can ha%e child
indos" /n this chain of indos$ each child indo is called a descendant indo of the
original parent indo"
deseriali3ation
:e+creating an ob)ect by reading its state from persistent storage (usually a file) and
reconstructing it in memory" 2ee also seriali3ation"
7isual C## Pro)ect file
Formerly !non as the "M,C file" The pro)ect build file that specifies ho to build a particular
pro)ect in a pro)ect or!space" The file contains source file names and locations$ build settings$
and debug settings$ including brea!points and atches" /n terms of source control$ "02P files
can be shared"
7isual C## Wor!space file
, file created and maintained by 7isual C## that contains information formerly stored as part
of the "M0P file" The file contains information about the pro)ect or!space such as a list of all
the pro)ects" This file is used by 7isual C## and should not be edited by the user" /n terms of
source control$ the "02W file can be shared"
0e%elopment en%ironment
/n Microsoft 7isual 2tudio$ an integrated set of Windos+based tools for completing$ testing$
and refining an application" Microsoft 7isual 2tudio includes such features as %arious editors$
pro)ect build facilities$ compiler$ an incremental lin!er (for C##)$ class %ieer$ and an integrated
debugger"
0e%ice conte&t
, data structure defining the graphic ob)ects$ their associated attributes$ and the graphic
modes affecting output on a de%ice" 2ee also graphic ob)ect$ metafile"
0ialog bo&
/n Windos$ a child indo used to retrie%e user input" , dialog bo& usually contains one or
more controls$ such as buttons$ list bo&es$ combo bo&es$ and edit bo&es$ ith hich the user
enters te&t$ chooses options$ or directs the action of the command"
&$%&'
0ialog data e&change
/n MFC$ a method for transferring data beteen the controls of a dialog bo& and their
associated %ariables" 00U is an easy ay to initiali3e the controls in a dialog bo& and to gather
data input by the user" 2ee also dialog data %alidation (007)"
0ocument
9" (noun) ,ny self+contained piece of or! created ith an application program and$ if
sa%ed on dis!$ gi%en a uni=ue filename by hich it can be retrie%ed"
6" (%erb) To e&plain or annotate something$ such as comments ithin a program or a
description of a problem in a bug report"
0ocument(%ie architecture
, design methodology that focuses on hat the user sees and needs rather than on the
application or hat the application re=uires" This design is implemented by a set of classes that
manage$ store and present application+specific data" These classes can manipulate dis!+based
data files (document ob)ects)$ display a document;s data (%ie ob)ects)$ and automatically use a
particular type of indo (indo ob)ects)"
.&ception
,n abnormal condition or error that occurs during the e&ecution of a program and that re=uires
the e&ecution of softare outside the normal flo of control" .&amples of e&ceptions are
running out of memory$ resource allocation errors$ and failure to find files" 2ee also C##
e&ception handling$ structured e&ception handling (2.>)"
.&ecutable file
, program file created from one or more source code files translated into machine code and
lin!ed together" The M2+0-2$ Windos$ and Windos BT operating systems use the ".U.
filename e&tension to indicate that the file is a runnable program"
Focus
, temporary property of a user+interface ob)ect$ such as a indo$ %ie$ dialog bo&$ or button$
that permits the ob)ect to recei%e !eyboard input from the user" The focus is usually con%eyed
through highlighting" 2ee also top+le%el indo"
Font resource
, group of indi%idual fonts representing characters in a gi%en character set that ha%e %arious
combinations of heights$ idths$ and pitches" The Windos operating system maintains a font
table containing all the fonts that applications can use" ?ou can load font resources and add the
fonts in each resource to this table by using the ,ddFont:esource Windos function
&(%&'
Frame indo
/n MFC$ the indo that coordinates the interactions of the application ith a document and its
%ie" The frame indo pro%ides a %isible frame around a %ie$ ith an optional status bar and
standard indo controls such as a control menu$ buttons to minimi3e and ma&imi3e the indo$
and controls for resi3ing the indo" The frame indo is responsible for managing the layout
of its child indos and other client+area elements such as control bars and %ies" The frame
indo also forards commands to its %ies and can respond to notification messages from
control indos" /n -L.$ a frame indo is the outermost main indo
@0/
,n e&ecutable program that processes graphical function calls from a Windos+based
application and passes those calls to the appropriate de%ice dri%er$ hich performs the
hardare+specific functions that generate output" 1y acting as a buffer beteen applications
and output de%ices$ @0/ presents a de%ice+independent %ie of the orld for the application
hile interacting in a de%ice+dependent format ith the de%ice"
>elp conte&t
, string and a number (>elp conte&t /0) that an application passes during a call to Windos
>elp in order to locate and display a >elp topic" 2ee also >elp map file$ >elp pro)ect file"
>elp file
, file that contains te&t and graphics needed to communicate online information about an
application" .ach help file contains one or more topics a user can select by clic!ing hot spots$
using the !eyord search$ or brosing through topics" >elp files ha%e a ">LP filename e&tension"
2ee also >elp topic"
>ot !ey
9" /n Windos$ an application+defined !ey combination used to obtain high+priority
!eyboard input from the user" For e&ample$ an application can ha%e a hot !ey that allos
the user to cancel a lengthy operation"
6" , !ey combination that the user can create to perform an action =uic!ly" 2ee also
accelerator !ey"
Main frame indo
The primary indo responsible for coordinating the frame ith its %ie" /n an 20/ application$
the document frame indo is also the main frame indo" /n an M0/ application$ document
indos are child indos displayed in the main frame indo" The styles and other
characteristics of frame indos are inherited from the main frame+indo class"
Main message loop
The main loop in an application that retrie%es messages from a message =ueue and dispatches
them to the appropriate indo procedures" The main message loop ta!es o%er hen there is no
&)%&'
secondary loop to handle a particular message" .%ery application for Windos has a main
message loop" 2ee also message =ueue"
Ma!e file
, file that contains all commands$ macro definitions$ options$ and so on to specify ho to build
the pro)ects in a pro)ect or!space" , ma!efile has the filename e&tension "M,C and usually
has the same base name as the or!space configuration ("M0P) file"
M0/
The standard user+interface architecture for Windos+based applications" , multiple document
interface application enables the user to or! ith more than one document at the same time"
.ach document is displayed ithin the client area of the application;s main indo" 2ee also
child indo$ client area$ single document interface (20/)"
Menu resource
, collection of information that defines the appearance and function of an application menu"
This information includes the te&t strings that appear in an application;s menu bar$ menu+item
identifiers$ the arrangement of the menus and status of menu items
Message
, structure or set of parameters used for communicating information or a re=uest" Messages
can be passed beteen the operating system and an application$ different applications$ threads
ithin an application$ and indos ithin an application"
Message bo&
, indo that displays information to the user" For e&ample$ a message bo& can inform the user
of a problem that the application has encountered hile carrying out a tas!
Message handler
/n Windos$ an ob)ect$ such as a %ie or frame indo$ that pro%ides handler functions to
process messages"
Message handling
The act of responding to messages recei%ed from the operating system" ,pplications use
message+handling functions to process messages"
Message loop
, program loop that retrie%es messages from a thread;s message =ueue and dispatches them to
the appropriate indo procedures" 2ee also message =ueue"
&*%&'
Message map
, mechanism to route Windos messages and commands to the indos$ documents$ %ies$ and
other ob)ects in an MFC application" Message maps map Windos messages$ commands from
menus$ toolbar buttons$ accelerators and control+notification messages" , collection of macros
in a class;s source ("CPP) file specify hich functions ill handle %arious messages for the class"
nonsystem !ey
, !eyboard !ey that is pressed hen the ,LT !ey is not pressed or a !eyboard !ey that is
pressed hen a indo has the !eyboard focus"
Botification message
, message that a control sends to its parent indo hen e%ents$ such as input from the user$
occur"
-L.
Pronounced "o+L,?"" , ay to transfer and share information beteen applications" Lin!ing and
embedding are to methods in -L. for storing items inside a compound document hen those
items ere created in another application" ,n embedded item is stored as part of the compound
document that contains it" , lin!ed item stores its data in a separate file
-%erlapped indo
, style of indo meant to ser%e as an application;s main indo" -ther indos can o%erlap
the indo;s space on the screen"
:esource
9" , program bloc!$ dialog bo& template$ bitmap$ font$ or sound$ for e&ample$ that can be
used by more than one program or in more than one place in a program" The use of
resources allos alteration of many features in a program ithout the necessity of
recompiling the program from source code" 2ee also resource type"
6" More generally$ any part of a computer system or a netor! that can be allotted to a
program or a process hile it is running"
:esource script file"
, te&t file containing descriptions of resources from hich the resource compiler creates a
binary resource file" For Microsoft Windos applications$ resource+definition files usually ha%e
a ":C filename e&tension" For ,pple Macintosh applications$ such files are typically named ith a
": e&tension and ritten ith the ,pple :e3 script language" 2ee also compiled resource file"
&&%&'
20/
, user interface architecture that allos a user to or! ith )ust one document at a time"
Windos Botepad is an e&ample of an 20/ application" 2ee also multiple document interface
(M0/)"
20C
, set of libraries$ header files$ tools$ boo!s$ on+line help and sample programs designed to help
a de%eloper create softare"
2eriali3ation
9" -r ob)ect persistence" /n MFC$ the process of riting or reading an ob)ect to or from a
persistent storage medium$ such as a dis! file" The basic idea of seriali3ation is that an
ob)ect should be able to rite its current state$ usually indicated by the %alue of its
member %ariables$ to persistent storage" Later$ the ob)ect can be re+created by reading$
or deseriali3ing$ the ob)ect;s state from storage"
2ibling indo
, child indo that has the same parent indo as one or more other child indos
2ingle document interface
, user interface architecture that allos a user to or! ith )ust one document at a time"
Windos Botepad is an e&ample of an 20/ application" 2ee also multiple document interface
(M0/)"
2ystem modal dialog bo&
-r system modal message bo&$ system modal indo" , dialog bo& that pre%ents the user from
doing anything else in Windos until the dialog bo& is cleared$ usually by choosing a pushbutton
mar!ed either -C or Cancel" 4se a system modal dialog bo& to notify the user of serious$
potentially damaging errors that re=uire immediate attention (for e&ample$ running out of
memory)"
Thread
The basic entity to hich the operating system allocates CP4 time" , thread can e&ecute any
part of the application;s code$ including a part currently being e&ecuted by another thread" ,ll
threads of a process share the %irtual address space$ global %ariables$ and operating+system
resources of the process"
7ersion information
,n application;s company and product identification$ product release number$ and copyright and
trademar! notification" 7ersion information is held in a standard form in the e&ecutable (".U.)
file or dynamic+lin! library (0LL) file and is accessible by %arious tools and Windos functions"
&+%&'
Windo class
, set of attributes that Microsoft Windos uses as a template to create a indo in an
application" Windos re=uires that an application supply a class name$ the indo+procedure
address$ and an instance handle" -ther elements may be used to define default attributes for
indos of the class$ such as the shape of the cursor and the content of the menu for the
indo
Windo style
, named constant that defines an aspect of the indo;s appearance and beha%ior not specified
by the indo;s class"
Wi3ard
, special form of user assistance that guides the user through a difficult or comple& tas!
ithin an application" For e&ample$ a database program can use i3ards to generate reports and
forms" /n 7isual C##$ the ,ppWi3ard generates a s!eleton program for a ne C## application"
&'%&'

You might also like