Visual C Programming How to draw 3 - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Visual C Programming How to draw 3

Description:

Visual C++ Programming How to draw 3 Department of Digital Contents Sang Il Park – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 46
Provided by: SEJ94
Category:

less

Transcript and Presenter's Notes

Title: Visual C Programming How to draw 3


1
Visual C ProgrammingHow to draw 3
  • Department of Digital Contents
  • Sang Il Park

2
Outline
  • Review
  • How to draw with MFC 3

3
Review Device Context
4
Review CPaintDC ???
  • ??? WM__PAINT ??? ?????? ??
  • OnPaint()
  • CPaintDC ?? ?

void CChildViewOnPaint() CPaintDC
dc(this) // ...
5
Review CClientDC ???
  • WM_PAINT ??? ??? ??? ???? ??
  • CClientDC ?? ?

void CChildViewOnLButtonDown(UINT nFlags,
CPoint point) CClientDC dc(this) // ...
6
Review CWindowDC ???
  • CWindowDC ?? ??
  • CPaintDC, CClientDC ???? ??
  • ?? ??

7
Review CMetaFileDC ???
  • ?? ??(Metafile)
  • GDI ???? ??? ? ?? ??
  • CMetaFileDC ?? ??
  • CMetaFileDC ??? ?? ? CMetaFileDCCreate() ??
  • ?? ?? ??? ???? ???? ???? ??? ???? ?? ?? ?? ??? ??
  • CMetaFileDCClose()? ???? ??? ????? ????? ?? ???
    ?? ? ?? ?? ??(HMETAFILE ??)? ??
  • CDCPlayMetaFile()? ?? ??? ??

8
Review ??? ?? (1/3)
  • ? ??

COLORREF color dc.GetPixel (x,y) dc.SetPixelV(x
,y, RGB(r,g,b))
9
Review ??? ?? (2/3)
  • ?? ???

(x1, y1)
dc.Rectangle (x1, y1, x2, y2) dc.Ellipse (x1,
y1, x2, y2)
(x2, y2)
9
10
Review ??? ?? (2/3)
  • ?? ???? ?? ???

CRect rect GetClientRect(rect)
11
Review ??? ?? (3/3)
  • ? ???

(x1,y1)
dc.MoveTo(x1,y1) dc.LineTo(x2,y2)
(x2,y2)
12
Review ??? ??
  • ??? ?? ??

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
13
Review ?? ?? ??
CDCSetMapMode (MappingMode)
14
Review ?? ??
  • ?? ?? ??

15
How to draw with MFC 3
16
GDI? ???? ??? ??? ?
  • ???
  • ?? ???? ??? ?? ? ????
  • Pen? ??? ??? ?
  • Brush? ??? ??? ?

17
GDI ?? (1/3)
  • GDI ??
  • GDI?? ??? ? ???? ??
  • ??

18
GDI ?? (2/3)
  • ??? ???

19
GDI ?? (3/3)
  • GDI ?? ?? ??
  • GDI ??? ??? ????.
  • ??? GDI ??? ???? ????? ???? ??? ???? ?? ?? ???
    GDI ??? ??? ?????(CDCSelectObject() ??).
  • GDI ??? ???? ??? ??.
  • ??? GDI ??? ???? ????? ?????? ??? ??? GDI ??? ??
    ????(CDCSelectObject() ??).
  • GDI ??? ??(Scope)? ???? ???? ???? ????? ????.

20
GDI ?? (3/3)
  • ??? ??? ?? (???? ??)
  • Pen? ???.
  • Pen? ????.
  • ??? ???.
  • Pen? ???.

21
GDI ?? (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)
  • ?? ? 1
  • ?? ? 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)
  • ?? ? 1
  • ?? ? 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() ??? ???? ???? ????? ????.

29
CRgn ???(?)? ?? ?? ??
  • ??? (Polygon)

30
CRgn ???(?)? ?? ?? ??
  • ????

?? ??
? ??
style
CRgn rgn rgn.CreatePolygonRgn( CPoint pt, int
nNumber, int nStyle) dc.PaintRgn(rgn)
nStyle ALTERNATE or WINDING
31
CRgn ???(?)? ?? ?? ??
  • ??

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
???
  • ??? dot(pixel)? ?? ?? ?

33
??? ??? ??? ???
  • ??? ??? ??? ??? ??

34
Cbitmap ???? ???? ??
  • ???1 Brush? ??

??? ???
CBitmap bitmap bitmap.LoadBitmap(IDB_BITMAP1) C
Brush brush(bitmap) dc.SelectObject(brush) dc.
Rectangle(0,0,200,200)
35
CBitmap
  • ??? ??

int CBitmapGetBitmap (BITMAP pBitMap)
struct BITMAP int bmType int
bmWidth // ???? ?(?? ??) int bmHeight
// ???? ??(?? ??) int bmWidthBytes
BYTE bmPlanes BYTE bmBitsPixel LPVOID
bmBits
36
CBitmap
  • ??? ?? ??

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)
40
CBitmap
  • ??? ?? ??

??? ???? ?? SRCCOPY,
BOOL BitBlt (int x, int y, int nWidth, int
nHeight, CDC pSrcDC, int xSrc, int ySrc, DWORD
dwRop)
nWidth
nHeight
41
CBitmap
  • ??? ?? ?? (cont'd)

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
42
Memory? ????? ????
  • ??
  • 1. ???DC ??? (CreateCompatibleDC)
  • 2. ???? ??? ??? (CreateCompatibleBitmap)
  • 3. DC? Bitmap? ?? (SelectObject)
  • 4. ?? ???
  • 5. ??? ??? ??DC? BitBlt

????
43
Memory? ????? ????
????
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)
44
Double Buffering using bitmap
  • ??? ?? ????.
  • ??? ??? ???????
  • ? ??? ?? ??? ??? ??!
  • ? ??? ?? ??? ???? ???? ??? ??? ??? ??.
  • ? WM_ERASEBKGND

45
?? 2
  • ???? ??? (4? 1?)
  • ???? ??? ? ?? ??? ????? ??
  • ???(??? ?? ??), ?(??? ?? ??)
  • ?? ???? ?? ??
  • Double Buffering
  • ??? ???? ?? ???(?) ??? ?? ??
  • Bells and Whistles Extra Point
  • ??? ???
  • ?? ??
Write a Comment
User Comments (0)
About PowerShow.com