0% found this document useful (0 votes)
124 views

Microsoft Foundation Classes

The MFC (Microsoft Foundation Classes) provides an object-oriented approach to Windows programming by encapsulating the Windows API in a set of predefined classes. The MFC uses the document/view concept where a document stores application data and views provide mechanisms to display and interact with the document. Developers create document and view classes derived from MFC classes to take advantage of built-in functionality and ease of implementation.

Uploaded by

Sultan Zia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Microsoft Foundation Classes

The MFC (Microsoft Foundation Classes) provides an object-oriented approach to Windows programming by encapsulating the Windows API in a set of predefined classes. The MFC uses the document/view concept where a document stores application data and views provide mechanisms to display and interact with the document. Developers create document and view classes derived from MFC classes to take advantage of built-in functionality and ease of implementation.

Uploaded by

Sultan Zia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

MFC

Microsoft Foundation Classes


Windows API
• Comes as part of every copy of windows
• A large Set of Functions (over a thousand)
• Provide all necessary services and communications
MFC
• Set of predefined Classes
• An OO approach to Windows programming
• Encapsulates the Windows API
• The Process of Windows Programming Involves
– Creating and using MFC Objects
– Objects of classes derived from MFC
Document/View Concept

What is Document?
Collection of Data in your Application

Your Document class is derived from MFC class CDocument

You’ll add data members here to store items and member functions
to support processing

Why?

Standard Mechanism provided within MFC

You’ll get a broad range of built in functionality

Speed

Ease of Implementation

Etc
What is View?
• An object which provides a mechanism to display some or all of the
data stored in
document
• A view always relates to a particular document object

• How the data is to be displayed in a window

• How the user interact with it

• A document can have multiple view objects associated with it

• MFC incorporates a mechanism for integrating a Document with its


View.
private:
CArray <CPoint , CPoint&> myArray;
int index;
// Operations
public:

// Overrides
// ClassWizard generated virtual function
overrides
//{{AFX_VIRTUAL(CDrawingDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL

void SetValue(CPoint);
CPoint GetValue(int);
CDrawingDoc::CDrawingDoc()
{
// TODO: add one-time construction code here
myArray.SetSize(10);
index = 0;

CDrawingDoc::SetValue(CPoint pt)
{
myArray[index++] = pt;
}

CPoint CDrawingDoc::GetValue(int i)
{
return myArray[i];
}
void CDrawingView::OnDraw(CDC* pDC)
{
CDrawingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPoint pt;
CRect rectangle;
pt.x = 50;
pt.y = 50;
pDoc->SetValue(pt);
pt.x = 200;
pt.y = 200;
pDoc->SetValue(pt);
CPen mypen;
if(!mypen.CreatePen(PS_SOLID , 4 , RGB(200 ,0,0)))
{
AfxMessageBox("Pen Creation Error");
AfxAbort();
}
CPen* oldPen = pDC->SelectObject(&mypen);
CBrush myBrush;
myBrush.CreateHatchBrush(HS_DIAGCROSS , RGB(5,5,215));
CBrush* oldBrush = static_cast<CBrush*>(pDC->SelectObject(&myBrush));
//CBrush* oldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));
rectangle = CRect(pDoc->GetValue(0) , pDoc->GetValue(1));
rectangle.NormalizeRect();
pDC->Rectangle(rectangle);
pDC->SelectObject(oldPen);
pDC->SelectObject(oldBrush);
Good Luck

You might also like