Title: Visual C Programming How to draw 3
1Visual C ProgrammingHow to draw 3
- Department of Digital Contents
- Sang Il Park
2Outline
- Review
- How to draw with MFC 3
3Review Device Context
4Review CPaintDC ???
- ??? WM__PAINT ??? ?????? ??
- OnPaint()
- CPaintDC ?? ?
void CChildViewOnPaint() CPaintDC
dc(this) // ...
5Review CClientDC ???
- WM_PAINT ??? ??? ??? ???? ??
- CClientDC ?? ?
void CChildViewOnLButtonDown(UINT nFlags,
CPoint point) CClientDC dc(this) // ...
6Review CWindowDC ???
- CWindowDC ?? ??
- CPaintDC, CClientDC ???? ??
- ?? ??
7Review CMetaFileDC ???
- ?? ??(Metafile)
- GDI ???? ??? ? ?? ??
- CMetaFileDC ?? ??
- CMetaFileDC ??? ?? ? CMetaFileDCCreate() ??
- ?? ?? ??? ???? ???? ???? ??? ???? ?? ?? ?? ??? ??
- CMetaFileDCClose()? ???? ??? ????? ????? ?? ???
?? ? ?? ?? ??(HMETAFILE ??)? ?? - CDCPlayMetaFile()? ?? ??? ??
8Review ??? ?? (1/3)
COLORREF color dc.GetPixel (x,y) dc.SetPixelV(x
,y, RGB(r,g,b))
9Review ??? ?? (2/3)
(x1, y1)
dc.Rectangle (x1, y1, x2, y2) dc.Ellipse (x1,
y1, x2, y2)
(x2, y2)
9
10Review ??? ?? (2/3)
CRect rect GetClientRect(rect)
11Review ??? ?? (3/3)
(x1,y1)
dc.MoveTo(x1,y1) dc.LineTo(x2,y2)
(x2,y2)
12Review ??? ??
dc.SetTextColor(RGB(255,0,0)) dc.SetBkColor(RGB(0
,255,0)) dc.SetTextAlign(TA_CENTER) dc.TextOut(3
00,200,Sejong University)
http//msdn2.microsoft.com/ko-kr/library/e37h9k5s(
VS.80).aspx
13Review ?? ?? ??
CDCSetMapMode (MappingMode)
14Review ?? ??
15How to draw with MFC 3
16GDI? ???? ??? ??? ?
- ???
- ?? ???? ??? ?? ? ????
- Pen? ??? ??? ?
- Brush? ??? ??? ?
17GDI ?? (1/3)
- GDI ??
- GDI?? ??? ? ???? ??
- ??
18GDI ?? (2/3)
19GDI ?? (3/3)
- GDI ?? ?? ??
- GDI ??? ??? ????.
- ??? GDI ??? ???? ????? ???? ??? ???? ?? ?? ???
GDI ??? ??? ?????(CDCSelectObject() ??). - GDI ??? ???? ??? ??.
- ??? GDI ??? ???? ????? ?????? ??? ??? GDI ??? ??
????(CDCSelectObject() ??). - GDI ??? ??(Scope)? ???? ???? ???? ????? ????.
20GDI ?? (3/3)
- ??? ??? ?? (???? ??)
- Pen? ???.
- Pen? ????.
- ??? ???.
- Pen? ???.
21GDI ?? (3/3)
- ??? ??? ?? (GDI????)
- ??? ??(pen)? ????.
- DC? ? ??? ??? ??. (CDCSelectObject())
- ??? ???.
- ??? ??? ???? ??.
(??? ??? ?? ??? ????)
(??? ??? ?? ??? ??)
22? (1/2)
???
?
?
// ?? 1 CPen pen(PS_SOLID, 2, RGB(255, 0,
0)) // constructor // ??2 CPen
pen pen.CreatePen (PS_SOLID, 2, RGB (255, 0,
0)) // ?????
23? (2/2)
CPaintDC dc(this) CPen pen(PS_SOLID, 1,
RGB(0, 0, 255)) CPen pOldPen
dc.SelectObject(pen) dc.Rectangle(100, 100,
200, 200) dc.SelectObject(pOldPen)
CPaintDC dc(this) CPen pen(PS_SOLID, 1, RGB(0,
0, 255)) dc.SelectObject(pen) dc.Rectangle(100,
100, 200, 200)
24??? (1/2)
25??? (2/2)
CPaintDC dc(this) CBrush brush(RGB(255, 0,
0)) CBrush pOldBrush dc.SelectObject(brush)
dc.Ellipse(100, 100, 200, 200) dc.SelectObject(pO
ldBrush)
CPaintDC dc(this) CBrush brush(RGB(255, 0,
0)) dc.SelectObject(brush) dc.Ellipse(100,
100, 200, 200)
26?? (1/2)
- ?? ??
- CFont ?? ??
- CFont ??? ?? CreateFont() ??? ??
CFont font font.CreateFont(...) //
font.CreateFontIndirect(...) //
font.CreatePointFont(...) // font.CreatePointFont
Indirect(...)
27?? (2/2)
CPaintDC dc(this) CFont font font.CreatePointFon
t(400, "Arial) dc.SelectObject(font) dc.TextOu
t(10, 10, "Hello)
28?? ??
- CDCSelectStockObject() ??? ???? ???? ????? ????.
29CRgn ???(?)? ?? ?? ??
30CRgn ???(?)? ?? ?? ??
?? ??
? ??
style
CRgn rgn rgn.CreatePolygonRgn( CPoint pt, int
nNumber, int nStyle) dc.PaintRgn(rgn)
nStyle ALTERNATE or WINDING
31CRgn ???(?)? ?? ?? ??
CPaintDC dc(this) CRgn rgn CPoint
ptVertex5 ptVertex0 CPoint(180,80) ptVerte
x1 CPoint(100,160) ptVertex2
CPoint(120,260) ptVertex3 CPoint(240,260) pt
Vertex4 CPoint(260,160) rgn.CreatePolygonRgn
( ptVertex, 5, ALTERNATE) dc.PaintRgn(rgn)
32???
33??? ??? ??? ???
34Cbitmap ???? ???? ??
??? ???
CBitmap bitmap bitmap.LoadBitmap(IDB_BITMAP1) C
Brush brush(bitmap) dc.SelectObject(brush) dc.
Rectangle(0,0,200,200)
35CBitmap
int CBitmapGetBitmap (BITMAP pBitMap)
struct BITMAP int bmType int
bmWidth // ???? ?(?? ??) int bmHeight
// ???? ??(?? ??) int bmWidthBytes
BYTE bmPlanes BYTE bmBitsPixel LPVOID
bmBits
36CBitmap
CBitmap bitmap bitmap.LoadBitmap(IDB_BITMAP1) BI
TMAP bmpinfo bitmap.GetBitmap(bmpinfo) CString
str.Format("?? d, ?? d\n",
bmpinfo.bmWidth, bmpinfo.bmHeight) dc.TextOut(100
,100,str)
37???? ?? ?????
- ? ?? ??? ?? ???? ???? ??? (Block)
(Transfer) - ??
- ??? ???? ??
- ? ?? ??? ??
- ? ???? ?? ???
- ??? ???? ??? ?????
38???? ?? ?????
- ? ?? ??? ?? ???? ???? ??? (Block)
(Transfer) - ??
- ??? ???? ?? CPaintDC dc
- ? ?? ??? ?? CDCCreateCompatibleDC(..)
- ? ???? ?? ??? CDCSelectObject()
- ??? ???? ??? ????? dc.BitBlt()
39??? ?? ??
CPaintDC dc(this) CBitmap bitmap bitmap.LoadBit
map(IDB_BITMAP1) BITMAP bmpInfo bitmap.GetBitmap
(bmpInfo) CDC memDc memDc.CreateCompatibleDC(
dc) memDc.SelectObject(bitmap) dc.BitBlt(100,
100, bmpInfo.bmWidth, bmpInfo.bmHeight,
memDC, 0, 0, SRCCOPY)
40CBitmap
??? ???? ?? SRCCOPY,
BOOL BitBlt (int x, int y, int nWidth, int
nHeight, CDC pSrcDC, int xSrc, int ySrc, DWORD
dwRop)
nWidth
nHeight
41CBitmap
BOOL StretchBlt (int x, int y, int nWidth, int
nHeight, CDC pSrcDC, int xSrc, int ySrc, int
nSrcWidth, int nSrcHeight, DWORD dwRop)
pSrcDC (??? ???? ????)
ySrc
nSrcWidth
xSrc
nSrcHeight
(??? ???? ????)
y
nWidth
x
nHeight
42Memory? ????? ????
- ??
- 1. ???DC ??? (CreateCompatibleDC)
- 2. ???? ??? ??? (CreateCompatibleBitmap)
- 3. DC? Bitmap? ?? (SelectObject)
- 4. ?? ???
- 5. ??? ??? ??DC? BitBlt
????
43Memory? ????? ????
????
CPaintDC dc(this) CRect rect GetClientRect(rec
t) CDC memDC memDC.CreateCompatibleDC(dc) CBi
tmap bitmap bitmap.CreateCompatibleBitmap(dc,rec
t.Width(),rect.Height()) memDC.SelectObject(bitm
ap) memDC.Rectangle(0,0,100,100)
dc.BitBlt(0, 0, rect.Width(), rect.Height(),
memDC, 0, 0, SRCCOPY)
44Double Buffering using bitmap
- ??? ?? ????.
- ??? ??? ???????
- ? ??? ?? ??? ??? ??!
- ? ??? ?? ??? ???? ???? ??? ??? ??? ??.
- ? WM_ERASEBKGND
-
45?? 2
- ???? ??? (4? 1?)
- ???? ??? ? ?? ??? ????? ??
- ???(??? ?? ??), ?(??? ?? ??)
- ?? ???? ?? ??
- Double Buffering
- ??? ???? ?? ???(?) ??? ?? ??
- Bells and Whistles Extra Point
- ??? ???
- ?? ??