11 Introduction To MFC
11 Introduction To MFC
Foundation Classes
Background on Object Oriented
Programming
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
• Modularity
• General-Purpose classes
– CObject, CException
• Windows API classes
– CCmdTarget, CWinThread, CWinApp
• Application framework classes
– CDocument, CView
• High Level abstractions
– ScrollView, Splitter
• CWinApp
• CWnd
• CFrameWnd
• CView
• CDocument
• Represents a window
• Used for display purposes
• Also receives events
• Minimum application
• Event handling
• Window painting
• Menus
• Dialog boxes
BOOL CGenericApp::InitInstance() {
m_pMainWnd = new CGenericWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CGenericApp GenericApp;
GUID, FPGDST 2004-2005, C-DAC
Analysis..
• This program looks different from a C/SDK program
– The WinMain() function is gone, and
– There is no code that seems to be registering the window
classes
• There is no message handling function anywhere
– It seems the message loop hasn’t been created
• Most of the implementation details have been hidden
from the programmer
– The framework does most of the job for the programmer and
have been hidden inside macros like
BEGIN_MESSAGE_MAP
GUID, FPGDST 2004-2005, C-DAC
..Analysis
• WinMain() is part of the application framework and
MFC’s
– WinMain() does a very good job initializing the variables,
creating the window and setting up the message loop
• The function InitInstance() is called by the WinMain()
– Handles the creation of the window and registers the
window classes too
• MFC’s message handling still uses the same functions
GetMessage(), TranslateMessage() and
DispatchMessage()
– But at the lowest level because these functions have been
encapsulated
GUID, FPGDST 2004-2005, C-DAC
The IDE
To view/add/edit
messages,
handler
functions, Select UI
member controls
variables by here
ClassWizard
Add your
codes for
handling click
event here
GUID, FPGDST 2004-2005, C-DAC
References
• MSDN Online
• Beginning Visual C++ 6
– Ivor Horton, Wrox Publication
• Learn Microsoft Visual C++ 6.0 Now
– Chuck Sphar, Microsoft Press
• Samples
– min
– appwiz