【MFC系列-第20天】CDC绘图类成员介绍
20.1 三大坐標系:屏幕、客戶區和非客戶區
20.2 三大派生類:
a)CPaintDC(客戶區標準繪圖),內部封裝函數是:BeginPaint和EndPaint
b)CClientDC(客戶區非標準繪圖),內部是:::GetDC和ReleaseDC
(CWnd::GetDC的功能有寫重復)和ReleaseDC
CDC* pDC = this->GetDC(); // CWnd::GetDC(非靜態) pDC->Ellipse(CRect(point.x-10,point.y-5,point.x+10,point.y+5)); this->ReleaseDC(pDC);//忘記了之后容易造成GDI泄漏,在任務管理器中可以觀察泄漏情況 CDialogEx::OnLButtonDown(nFlags,point);c)CWindowDC(非客戶區繪圖),內部是:GetWindowDC和ReleaseDC
d)CMemoryDC(內存DC),自己封裝
GetDC創建了一個新的GDI對象:忘記了ReleaseDC之后容易造成GDI泄漏??
20.3 基本圖形函數:
直線:MoveTo、LineTo,LineTo...
折線:PolyLine
多邊形(包括三角形):Polygon
矩形:Rectangle
圓形:Ellipse
圓角矩形:RoundRect
圓弧:Arc、(ArcTo也要與MoveTo連用)
餅形:Pie
GDI對象包括:HDC、HICON、HCURCOR、HPEN、HBRUSH、HFONT、HBITMAP、HRGN、HPALLETE
20.4 GDI對象之一——CPen類對象
兩對相反的函數是:CreatePenIndirect和GetLogPen,FromHandle和operator HPEN
CPen::CPen: Constructs a CPen object.
CPen::CreatePen: Creates a logical cosmetic or geometric pen with the specified style, width,
and brush attributes, and attaches it to the CPen object.
CPen::CreatePenIndirect: Creates a pen with the style, width, and color given in a LOGPEN structure, and attaches it to the CPen object.
CPen::FromHandle: Returns a pointer to a CPen object when given a Windows HPEN.
CPen::GetLogPen: Gets a LOGPEN underlying structure.
CPen::operator HPEN
構造
方法一
LOGPEN lp = { PS_DASHDOTDOT ,1,0,RGB(255,0,0)};if (!(HPEN)m_pen)//如果不是因為二義性編譯本不會出錯{m_pen.CreatePenIndirect(&lp);}方法二
m_pen.CreatePen(PS_DASHDOTDOT, 1, RGB(255, 0, 255));方法三
CPen pen(PS_SOLID, 3, RGB(255, 0, 0));20.5 GDI對象之二——CBrush類對象
兩對反函數
operator HBRUSH與FromHandle CreateBrushIndirect與GetLogBrushCBrush::CBrush: Constructs a CBrush object.
CBrush::CreateBrushIndirect
Initializes a brush with the style, color, and pattern specified in a LOGBRUSH structure.
CBrush::CreateDIBPatternBrush
Initializes a brush with a pattern specified by a device-independent bitmap (DIB).
CBrush::CreateHatchBrush:柵格
CBrush::CreatePatternBrush:位圖
CBrush::CreateSolidBrush:純色
CBrush::CreateSysColorBrush 系統顏色
CBrush::GetLogBrush Gets a LOGBRUSH structure.
CBrush::operator HBRUSH
20.6 GDI對象之三——CFont類對象
兩對反函數:
CreateFontIndirect和GetLogFont CFont::operator HFONT和CFont::FromHandleCFont::CFont Constructs a CFont object.
CFont::CreateFont: Initializes a CFont with the specified characteristics.
CFont::CreateFontIndirect:最常用標準創建字體
CFont::CreatePointFont簡易創建字體
CFont::GetLogFont獲取字體描述
CFont::operator HFONT
LOGFONT
lfFaceName 字體名稱
lfHeight:子體大小
lfCharSet:GB2312_CHARSET
lfWeight :粗度(400是Normal,700是粗體)
lfWidth 一般是字體大小的一半
lfItalic 斜體;
lfUnderline 下劃線;
lfStrikeOut 刪除線;
lfEscapement:360的10倍,比如2700代表270度。
方法一
LOGFONT lf = {24};// lf.lfCharSet = GB2312_CHARSET;// lf.lfWidth = 14; _tcscpy_s(lf.lfFaceName,_countof(lf.lfFaceName), _T("華文彩云")); m_font.CreateFontIndirect(&lf);方法二
if (!m_font.m_hObject)m_font.CreatePointFont(120, _T("宋體"));輸出
CFont* pOldFont = dc.SelectObject(&m_font);dc.SetBkColor(RGB(0, 255, 0));dc.SetBkMode(TRANSPARENT);dc.SetTextColor(RGB(255,0,0));dc.TextOut(100, 100, _T("測試CFont類字體創建函數!"));pOldFont->GetLogFont(&lf);總結
以上是生活随笔為你收集整理的【MFC系列-第20天】CDC绘图类成员介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雅利安人的起源和历史(雅利安人最早是来自
- 下一篇: 【MFC系列-第21天】GDI算法实战—