Microsoft Foundation Classes
Microsoft Foundation Classes
Microsoft Foundation Classes
You’ll add data members here to store items and member functions
to support processing
Why?
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
// 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