日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【MFC系列-第20天】CDC绘图类成员介绍

發布時間:2023/12/2 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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與GetLogBrush

CBrush::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::FromHandle

CFont::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绘图类成员介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。