Title: GDI? ???? ???? (1/5)
1(No Transcript)
2GDI? ???? ???? (1/5)
- ?? ???? ??? ? ??? ??
- ???, ??? ??, ??? ? ??? ???? ?? ??? ???? ????
????? ??? ??? ??? ??. - ?? ????? ??? ???? ????? ??? ????? ??? ??? ??? ???
??? ??. ? ???? ?? ?? ??? ?? ??(Direct Access)???
???? ???? ?? ???? ???? ??? ??.
3- GDI(Graphic Device Interface)
4GDI? ???? ???? (2/5)
- GDI(Graphics Device Interface)
- ????? ?? ??? ? ???? DLL? ??
- ????? ??? ?, ?, ???, ???, ?, ???, ??? ?? ???? ??
??? ??? - ? ?? ???? ???? CDC ????
?? ????
GDI
?? ?? (??, ??? ?)
?? ???
?? ???
5GDI? ???? ???? (3/5)
- ?? ??? ? ??? ??
- ????? ??? ????? ??? ???? ??? ??? ??? ??.
- ??? ?? ?? ???? ?? ? ?? ??? ?? ???? ??? ???? ???
??. - ?? ??? ??? ?? ???? ????? ??? ? ? ??? ??.
6GDI? ???? ???? (4/5)
- ???? ????(DC, Device Context)
- GDI? ???? ???? ??? ???
- ?????(?????) GUI ???? ??? ? ?? ?? ??? ??? ?? ??
- ?, ??, ???? ???? ?? ?? ???
- ???? ???
7?? ?? (1/3)
8?? ?? (2/3)
- WM_PAINT?? ???? ???
- WM_PAINT ??? ??
- HelloSDK
- HelloMFC
case WM_PAINT hdc BeginPaint(hwnd, ps)
TextOut(hdc, 100, 100, str, lstrlen(str))
EndPaint(hwnd, ps) return 0
void CMainFrameOnPaint() char msg
"Hello, MFC" CPaintDC dc(this)
dc.TextOut(100, 100, msg, lstrlen(msg))
9?? ?? (3/3)
- WM_PAINT ??? ?? ??
- ???? ??? ?
- ???? ??? ??? ?
- ??? ?? ??? ??? ?
- ?? ???? ???? ??? ?
- ?? ?? ??
void CWndInvalidate (BOOL bErase TRUE) void
CWndInvalidateRect (LPCRECT lpRect, BOOL bErase
TRUE)
10??? ???? ???? ???
11CPaintDC ???
void CChildViewOnPaint() CPaintDC
dc(this) // ...
12CClientDC ???
void CChildViewOnLButtonDown(UINT nFlags,
CPoint point) CClientDC dc(this) // ...
13CWindowDC ???
- CWindowDC ?? ??
- CPaintDC, CClientDC ???? ??
- ?? ??
14CMetaFileDC ???
- ?? ??(Metafile)
- GDI ???? ??? ? ?? ??
- CMetaFileDC ?? ??
- CMetaFileDC ??? ?? ? CMetaFileDCCreate() ??
- ?? ?? ??? ???? ???? ???? ??? ???? ?? ?? ?? ??? ??
- CMetaFileDCClose()? ???? ??? ????? ????? ?? ???
?? ? ?? ?? ??(HMETAFILE ??)? ?? - CDCPlayMetaFile()? ?? ??? ??
15??? ?? (1/3)
- SetPixel(x???, y???, RGB?) ??? ?????
- ??? ?? ?? ???, ?? ???? ???
16CDC ???? ??? ?? ???
- ?????
- Rectangle
- Ellipse
- Arc
- ??????
- TextOut
- DrawText
17??? ?? (1/3)
- MoveTo(x???, y ???) x,y ??? ????? ???.
- LineTo(x???, y ???) ?? ????? ??? 0,0
- ??? ???? ??. ????? ???? MoveTo
- ???? ??.
18??? ?? (2/3)
- ????
- (?? ??? (x1, y1) (x2,y2)? ?? ?? ???? ????)
- 1. ?? ??? (x1, y1)?? ???. ? MoveTo()?? ??
- dc.MoveTo(x1, y1)
- 2. ?? ???? (x2, y2)?? ?? ???. ? LineTo()?? ??
- dc.LineTo(x2, y2)
- ?) (10,10)?? (200,200) ? ?? ?? ???.
- CPaintDC dc(this)
- dc. MoveTo(10,10)
- dc.LineTo(200,200)
19??? ?? (3/3)
- Rectangle(x, y, width, height) ?? ??? x,y ????
? - ? width, ??? height? ??? ??
- Ellipse(x, y, width, height) ???? ?? ?, ? ??
?? - ??? ??? ??? ??.
20??? ??
21??? ??
- TextOut ??
- ??? ??? ???? ???? ???
- ????
- BOOL TextOut (x???, y???, ???, ?????)
- ??
- CClientDC dc(this)
- dc.TextOut(10,10, ?????)
- ? 10, 10 ??? ????? ??? ??
22??? ??
- DrawText ??
- ??? ????? ???? ???? ???
- ????
- int DrawText (???,LPRECT lprect, UINT nFormat)
- lprect ??? ?? ??
- nFormat ?? ?? ???
- ??
- CClientDC dc(this)
- CRect rect
- GetClientRect(rect)
- dc.DrawText(??????, rect,DT_CENTER)
- ? ??? ????? ??? ??
23??? ??
? ? ?
DT_TOP DT_BOTTOM DT_LEFT DT_RIGHT ??? lpRect??? ??(DT_TOP), ??(DT_BOTTOM), ??(DT_LEFT), ????(DT_RIGHT) ??? ?? ??. DT_SINGLELINE? ?? ???? ??? ??.
DT_CENTER ??? ??? ????? ?????
DT_VCENTER ??? ??? ?? ??? ?? ???. DT_SINGLELINE? ?? ???? ??? ??.
DT_EXPANDTABS ???? ?? ???? ?? ? ???? ?? ??. ???? 8??.
DT_CALCRECT ???? ??? ???? ??? ????. ?? ??? ???? ???.
DT_EXTERNALLEADING ??? ??? ??? ? external leading sapce? ?????.
DT_SINGLELINE ???? ?? ??? ???? ??? ????.
DT_NOCLIP ??? ?? ??? ????.
DT_NOPREFIX ??? ???? ???? ???. ????? ??? ???? ?? ?? ??? ??? ???.
DT_TABSTOP Flat ?? 8??? ?? ??? ???? ?????.
DT_WORDBREAK ???? ????? ???? ???? ????
24??? ??
- SetTextColor ??
- ???? ??? ?? ???? ???? ???
- ????
- COLORREF SetTextColor(COLORREF crColor )
- ??
- CClientDC dc(this)
- dc.SetTextColor(RGB(100,200,300))
//??? ?? - dc.TextOut(10,10, ?????)
- SetBkColor ??
- ???? ???? ???
- ????
- COLORREF SetBkColor(COLORREF crColor )
- ??
- CClientDC dc(this)
- dc.SetBkColor(RGB(255,255,0)) //???
?? -
25??? ??
- SetTextAlign ??
- ????? ?? ???? ????? ???
- ????
- UINT SetTextAlign(UINT fMode)
- fMode // ??? ?? ??
- TA_TOP ??? ??? ?? ??? ??.
- TA_BOTTOM ??? ??? ?? ??? ??.
- TA_CENTER ??? ??? ?? ?? ??? ??.
- TA_LEFT ??? ??? ?? ?? ??? ??.(??)
- TA_RIGHT ??? ??? ?? ??? ??? ??.
- TA_UPDATECP ??? ???? CP? ???? ??? ?? ?? CP?
????. - TA_NOUPDATECP CP? ???? ?? ??? ??? ???? CP? ????
???. -
26??? ??
- SetTextAlign ??
- ??
- dc.TextOut(70,0,"Hello World!")
- dc.SetTextAlign(TA_CENTER)
- dc.TextOut(70,20,"Hello World!") ? 70,20?
??? - dc.SetTextAlign(TA_RIGHT)
- dc.TextOut(70,40,"Hello World!")
27GDI ?? (1/3)
- GDI ??
- GDI?? ??? ? ???? ??
- ??
28GDI ?? (2/3)
293
DC????
Brush??
??
2
1
?? ?.
DC????
Brush??
5
4
30GDI ?? (3/3)
- GDI ?? ?? ??
- GDI ??? ??? ????.
- ??? GDI ??? ???? ????? ???? ??? ???? ?? ?? ???
GDI ??? ??? ?????(CDCSelectObject() ??). - GDI ??? ???? ??? ??.
- ??? GDI ??? ???? ????? ?????? ??? ??? GDI ??? ??
????(CDCSelectObject() ??). - GDI ??? ??(Scope)? ???? ???? ???? ????? ????.
31? (1/2)
// ?? 1 CPen pen(PS_SOLID, 2, RGB(255, 0,
0)) // ??2 CPen pen pen.CreatePen (PS_SOLID,
2, RGB (255, 0, 0))
32? (2/2)
CPaintDC dc(this) CPen pen(PS_SOLID, 1, RGB(0,
0, 255)) CPen pOldPen dc.SelectObject(pen) d
c.Rectangle(100, 100, 200, 200) dc.SelectObject(p
OldPen)
//??? ??
//?? ??? ??? ????? ?? ??? ? ?? ???.
//????
//?? ??? ???
CPaintDC dc(this) CPen pen(PS_SOLID, 1, RGB(0,
0, 255)) dc.SelectObject(pen) dc.Rectangle(100,
100, 200, 200)
//??? ??
//??? ?? ??? ???
//??? ??
33??? (1/2)
- ??? ??? ??? ?? ? ??? ???.
- ??
34??? (1/2)
CBrush brush(HS_DIAGCROSS, RGB(255, 0, 0))
35??? (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)
//DC?? ??
//????? ??
//?? ?? // ?? ?? ??
//?? ??
//?? ?? ??
CPaintDC dc(this) CBrush brush(RGB(255, 0,
0)) dc.SelectObject(brush) dc.Ellipse(100,
100, 200, 200)
//DC?? ??
//DC?? ??
//??? ?? ??
//????
36???
typedef struct tagLOGBRUSH UINT lbStyle
//??? ??? ?? COLORREF lbColor //?? ?? LONG
lbHatch //?? ?? LOGBRUSH
37???
CClientDC dc(this) //DC ?? ?? LOGBRUSH
logbrush // LOGBRUSH ??? ?? ?? //???? ???
?? logbrush.lbColor RGB(255,0,255) //?? ??
logbrush.lbStyle BS_HATCHED //??? ?? ?
?? logbrush.lbHatch HS_CROSS //??? ??
?? CBrush objectBrush //??? ?? ??
objectBrush.CreateBrushIndirect(logbrush)
//???? ??? LOGBRUSH ??? ?? ??
dc.SelectObject(br) //??? ?? ??
dc.Ellipse(point.x, point.y, point.x50,point.y50
)
38???
- CBrush CreateBrushIndirect ?? ??
BOOL CBrush CreateBrushIndirect (
const LOGBRUSH lpLogBrush )
- - LOGBRUSH ???? ???? ?? ???? ???
- ???? ???
- ?
CBrush objectBrush //??? ?? ??
objectBrush.CreateBrushIndirect(logbrush)
//???? ??? LOGBRUSH ??? ?? ??
39??? ????? ? ???
- CBitmap bitmap //CBitmap ???? ?? ??
- bitmap.LoadBitmap(IDB_BITMAP1)
- //IDB_BITMAP1 ??? ???? ??
- CBrush br(bitmap)
- //?? ???? ???
- dc.SelectObject(br) //??? ????? ??
- dc.Ellipse(point.x, point.y, point.x50,point.y5
0)
40??
- ?? ??
- CFont ?? ??
- CFont ??? ?? Create() ??? ??
CFont font font.CreateFont(...) //
font.CreateFontIndirect(...) //
font.CreatePointFont(...) // font.CreatePointFont
Indirect(...)
41??
- typedef struct tagLOGFONT // lf LONG
lfHeight // ?? LONG lfWidth // ? LONG
lfEscapement // ??? 10?? ???? ??? 100? ???.
LONG lfOrientation // ???? ??? LONG
lfWeight // ?? (?? 400 FW_NORMAL, BOLD 700
FW_BOLD ??) BYTE lfItalic // Italic BYTE
lfUnderline // ?? (TRUE) BYTE lfStrikeOut
// ??? (TRUE) BYTE lfCharSet // ??? (??? ,
0, ??? ??? 1 ) BYTE lfOutPrecision BYTE
lfClipPrecision BYTE lfQuality BYTE
lfPitchAndFamily TCHAR lfFaceNameLF_FACESIZE
// ?? LOGFONT
42??
- CreateFontIndirect LOGFONT ???? ??? ???? CFont
??? ?????. - CreateFont ??? ??? ???? CFont ??? ?????.
- CreatePointFont ???? 1/10? ??? ??? ??, ??? ???
?? CFont ??? ?????. - CreatePointFontIndirect ?? ??? ?? ???? 1/10?
??? ??? ??? ?? ?? CreateFontIndirect??? ?? ????.
43??
CPaintDC dc(this) CFont font font.CreatePointFon
t(400, "Arial") dc.SelectObject(font) dc.TextOu
t(10, 10, CString("Hello"))
44?? ??
- CDCSelectStockObject() ??? ???? ???? ????? ????.
45??? (1/5)
???? ??? ???? ??? ????.
int CBitmapGetBitmap (BITMAP pBitMap)
???? ??? ?? ???
typedef struct tagBITMAP int bmType
int bmWidth // ???? ?(?? ??) int bmHeight
// ???? ??(?? ??) int bmWidthBytes BYTE
bmPlanes BYTE bmBitsPixel LPVOID
bmBits BITMAP
46??? (2/5)
CBitmap bitmap bitmap.LoadBitmap(IDB_BITMAP1) BI
TMAP bmpinfo bitmap.GetBitmap(bmpinfo) CString
str Str.Format("?? d, ?? d\n",
bmpinfo.bmWidth, bmpinfo.bmHeight) dc.TextOut(10,
10,str)
47??? (3/5)
- ??? ??? ???? ??
- CDCCreateCompatibleDC()
- ??? ???? ????? ???.
- ??? ??? ??? ??? ??. ????? DC ??? ?? ??? ?? ???
DC? ?? ?? ?? - ?? ??
-
BOOL CreateCompatibleDC( CDC pDC )
48??? (4/5)
- ??? ??? ???? ??
- CDCBitBlt()
- ???? ??? ??? ?? ??? ??? ????.
- CDCStretchBlt()
- ???? ??? ??? ?? ??? ??? ???? ????.
49??? (4/5)
BOOL BitBlt (int x, int y, int nWidth, int
nHeight, CDC pSrcDC, int xSrc, int ySrc, DWORD
dwRop)
50??? (5/5)
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
51?? ??
52?? ?? (1/2)
53?? ?? (2/2)
54?? ??
55??? ??