180 likes | 345 Views
Microsoft Foundation Class (MFC). Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University. Outline. Application Wizard Microsoft Visual C++.Net 2003 Document-View CView::GetDocument CView::OnDraw
E N D
Microsoft Foundation Class(MFC) Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University
Outline • Application Wizard • Microsoft Visual C++.Net 2003 • Document-View • CView::GetDocument • CView::OnDraw • Device Contexts (DC) • Using CDC Pattern-Oriented Design
Application Wizard • Step One Pattern-Oriented Design
Application Wizard • Step Two 1. 2. 3. Pattern-Oriented Design
Application Wizard • Step Three Pattern-Oriented Design
Application Wizard • Step Four Pattern-Oriented Design
Application Wizard • Step Five Pattern-Oriented Design
Application Wizard • Step Six Pattern-Oriented Design
Application Wizard Pattern-Oriented Design
Document-View Pattern-Oriented Design
Document-View Pattern-Oriented Design
GetDocument Pattern-Oriented Design
OnDraw Pattern-Oriented Design
CDocument UpdateAllViews CView Invalidate Document-View Pattern-Oriented Design
Device Contexts • Device Contexts (DC) • Display • Printer • Direct v.s. Indirect • Memory • Information DC DR1 DR2 DR3 D1 D2 P1 D1 D2 P1 Pattern-Oriented Design
Device Context functions GetDC() ReleaseDC() … (see MSDN) HDC vs. CDC HDC: Win32 SDK CDC: MFC Device Contexts Pattern-Oriented Design
Using CDC void CF12345678View::OnDraw(CDC* /*pDC*/) { CF12345678Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: 在此加入原生資料的描繪程式碼 } Pattern-Oriented Design
Using CDC void CF12345678View::OnDraw(CDC* pDC) { CF12345678Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; CPen penRed(PS_SOLID, 1, RGB(255, 0, 0)); CPen * pOldPen; pOldPen = pDC->SelectObject(&penRed); pDC->SelectStockObject(HOLLOW_BRUSH); pDC->Ellipse(100, 100, 200, 200); pDC->SelectObject(pOldPen); } Pattern-Oriented Design