VC++ Programming UESTC Chapter 5 The Graphics Device Interface Color and Fonts Device context is the key gdi element that represents a physical device e The mfc cdc class has all the member functions that you ll need for drawing Except for the CMetaFiledC class, derived classes are distinct only in their constructor and destructor o For display and printer device context objects, framework attaches the handle to the object For memory device context, you must call a member function to attach the handle after construction
VC++ Programming @ UESTC 6 ⚫ Device context is the key GDI element that represents a physical device. ⚫ The MFC CDC class has all the member functions that you’ll need for drawing. ⚫ Except for the CMetaFileDC class, derived classes are distinct only in their constructor and destructor. ⚫ For display and printer device context objects, framework attaches the handle to the object. ⚫ For memory device context, you must call a member function to attach the handle after construction. Chapter 5 The Graphics Device Interface , Color and Fonts
VC++ Programming@UESTC Chapter 5 The Graphics Device Interface Color and Fonts o The Display Context Classes CClientDC and CWindowDC e CClientdc does not include menu bar. toolbar status bar and scroll bar o CWindowdC is more applicable to the frame windows than it is to the view windows
VC++ Programming @ UESTC 7 ⚫ The Display Context Classes CClientDC and CWindowDC ⚫ CClientDC does not include menu bar, toolbar, status bar and scroll bar. ⚫ CWindowDC is more applicable to the frame windows than it is to the view windows Chapter 5 The Graphics Device Interface , Color and Fonts
VC++ Programming UESTC Chapter 5 The Graphics Device Interface Color and Fonts Properly handle cdc object to release the windows resource Construct object object the stack void CMy View: OnLButton Down qUiNT nFlags Cpoint point) CRect rect CClientDC dc(this); / from stack dc. GetClipBox(rect):i//dc automatically released 2. Use CWnd: GetDC….. OnlButtondown(….){ Crect rect CDC* pDC= GetDCO ReleaseD(pDc); 3. You must not to destroy Cdc object passed by OnDraw. Let framework does it for you
VC++ Programming @ UESTC 8 ⚫ Properly handle CDC object to release the windows resource. 1. Construct object object the stack void CMyView::OnLButtonDown(UINT nFlags, Cpoint point) { CRect rect; CClientDC dc(this); // from stack dc.GetClipBox(rect); }// dc automatically released 2. Use CWnd::GetDC ….. OnLButtonDown(….) { Crect rect; CDC* pDC = GetDC(); …. ReleaseDC(pDC); } 3. You must not to destroy CDC object passed by OnDraw. Let framework does it for you. Chapter 5 The Graphics Device Interface , Color and Fonts
VC++ Programming UESTC Chapter 5 The Graphics Device Interface Color and Fonts e The State of the device Context What you see on screen or printer depends on the current state of device context Attached GDI drawing objects such as pens bruhes and fonts 2. The mapping mode that determines the scale of items then they are drawn 3. Various details such as alignment parameters and polygon filling mode
VC++ Programming @ UESTC 9 ⚫ The State of the Device Context What you see on screen or printer depends on the current state of device context. 1. Attached GDI drawing objects such as pens, bruhes and fonts. 2. The mapping mode that determines the scale of items then they are drawn. 3. Various details such as alignment parameters and polygon filling mode. Chapter 5 The Graphics Device Interface , Color and Fonts
VC++ Programming UESTC Chapter 5 The Graphics Device Interface Color and Fonts ● GDI Objects CGdiObject is the abstract base class for the gDi classes Derived Classes for Windows GDI objects Class windows handle type CPen HPEN CBrush HBRUSH CFont HFONT CBitmap HBITMAP PAlette HPALETTE CR HRGN 10
VC++ Programming @ UESTC 10 ⚫ GDI Objects CGdiObject is the abstract base class for the GDI classes. Derived Classes for Windows GDI Objects Class Windows handle type CPen HPEN CBrush HBRUSH CFont HFONT CBitmap HBITMAP CPalette HPALETTE CRgn HRGN Chapter 5 The Graphics Device Interface , Color and Fonts