Windows , . , .
:
(Pen) ();
(Brush) ;
(Font) ;
(Bitmap) .
Create..., (NULL ). , . , . . , , , .
Pen
, , , , (solid), (dotted) (dashed).
, , : BLACK _ PEN , WHITE _ PEN NULL _ PEN , .
, , hPen HPEN ( handle to a pen): HPEN hPen; , , ,
hPen = GetStockObject (WHITE_PEN);
,
SelectObject (hdc, hPen);
, .
:
hPen = SelectObject (hdc, GetStockObject (WHITE_PEN));
, SelectObject , ; , hPen ( ) , ,
SelectObject (hdc, hPen);
CreatePen CreatePenIndirect (ExtCreatePen).
CreatePen:
hPen = CreatePen (iPenStyle, iWidth, rgbColor);
iPenStyle ( ): PS _ SOLID , PS _ DASH, PS _ DOT, PS _ DASHDOT, PS _ DASHDOTDOT , , PS _ NULL () , PS _ INSIDEFRAME , .
|
|
PS _ SOLID, PS _ NULL PS _ INSIDEFRAME iWidth , iWidth = 0 .
rgbColor ; , PS _ INSIDEFRAME, , PS _ INSIDEFRAME 1.
, LOGPEN logpen ( logical pen), :
lopnStyle (UINT) ;
lopnWidth (POINT) ;
lopnColor (COLORREF) .
, CreatePenIndirect:
hPen = CreatePenIndirect (&logpen);
,
GetObject (hPen, sizeof(LOGPEN), &logpen);
CreatePen CreatePenIndirect . , , SelectObject.
, . , 3 . :
static HPEN hPen1, hPen2;
WM_CREATE :
hPen1 = CreatePen (PS_SOLID, 3, RGB (255, 0, 0));
hPen2 = CreatePen (PS_DOT, 0, 0);
WM_PAINT , , :
SelectObject (hdc, hPen2);
[ ]
SelectObject (hdc, hPen1);
[ ]
WM_DESTROY :
DeleteObject (hPen1);
DeleteObject (hPen2);
WM _ PAINT EndPaint.
CreatePen SelectObject :
SelectObject (hdc, CreatePen (PS_DASH, 0, RGB (255, 0, 0)));
, BLACK _ PEN , SelectObject:
DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN)));
, , SelectObject:
hPen = SelectObject (hdc, CreatePen (PS_DASH, 0, RGB (255, 0, 0)));
, hPen , (, SelectObject) :
DeleteObject (SelectObject (hdc, hPen));
Brush
, .
(Stock) : WHITE _ BRUSH , LTGRAY _ BRUSH -, GRAY _ BRUSH , DKGRAY _ BRUSH -, BLACK _ BRUSH NULL _ BRUSH (HOLLOW) .
, HBRUSH hBrush; , , GRAY _ BRUSH:
hBrush = GetStockObject (GRAY_BRUSH);
:
|
|
SelectObject (hdc, hBrush);
.
, NULL _ PEN:
SelectObject (hdc, GetStockObject (NULL_PEN));
, NULL _ BRUSH:
SelectObject (hdc, GetStockObject (NULL_BRUSH));
(Solid) :
hBrush = CreateSolidBrush (rgbColor);
(Hatch) , , :
hBrush = CreateHatchBrush (iHatchStyle, rgbColor);
iHatchStyle : HS _ HORIZONTAL, HS _ VERTICAL, HS _ BDIAGONAL ; HS _ FDIAGONAL ; HS _ CROSS ; HS _ DIAGCROSS ; rgbColor .
, OPAQUE, , TRANSPARENT, .
, , CreatePatternBrush:
hBrush = CreatePatternBrush (hBitmap);
, , :
hBrush = CreateBrushIndirect (&logbrush);
logbrush LOGBRUSH ( logical brush), :
UINT lbStyle : BS _ SOLID ; BS _ HOLLOW, BS _ NULL (); BS _ HATCHED ; BS _ PATTERN, BS _ PATTERN8X8 ; BS _ DIBPATTERN, BS _ DIBPATTERN8X8, BS _ DIBPATTERNPT DIB ( Windows 95 8´8 );
COLORREF lbColor , , DIB - , (DIB _ RGB _ COLORS) (DIB _ PAL _ COLORS).
lbStyle , :
lbStyle | lbColor | lbHatch |
BS _ SOLID | ||
BS _ HOLLOW | ||
BS _ HATCHED | ||
BS _ PATTERN |
: SelectObject (hdc, hBrush);
: DeleteObject (hBrush);
:
GetObject (hBrush, sizeof (LOGBRUSH), &logbrush);
Font
. .
( ) . GDI, , . , .
HFONT CreateFont (int nHeight, int nWidth, int nEscapement,
int nOrientation, int fnWeight, DWORD fdwItalic, DWORD fdwUnderline,
DWORD fdwStrikeOut, DWORD fdwCharSet,
DWORD fdwOutputPrecision, DWORD fdwClipPrecision,
DWORD fdwQuality, DWORD fdwPitchAndFamily,
LPCTSTR lpszFace);
(NULL ), :
nHeight () : , ( ), ; , ;
nWidth , 0 ;
|
|
nEscapement ( );
nOrientation ( , Windows 9x );
fnWeight 0 1000, : 0 (FW _ DONTCARE) ( ), 400 (FW _ NORMAL, FW _ REGULAR) , , 700 (FW _ BOLD) , , ..;
fdwItalic, fdwUnderline, fdwStrikeOut , , , ;
fdwCharSet : DEFAULT _ CHARSET, ANSI _ CHARSET, OEM _ CHARSET .. ( );
fdwOutputPrecision , : OUT _ DEFAULT _ PRECIS, OUT _ DEVICE _ PRECIS ..;
fdwClipPrecision ;
fdwQuality ;
fdwPitchAndFamily Ȼ , :
( ) 2 : DEFAULT _ PITCH, FIXED _ PITCH, VARIABLE _ PITCH;
4 : FF _ DONTCARE , FF _ MODERN , FF _ ROMAN ( ), FF _ SWISS ( ), FF _ SCRIPT ;
lpszFace , ; NULL , , .
CreateFontIndirect (const LOGFONT* lplgFont); .
.
COLORREF SetTextColor (hdc, crColor);
COLORREF GetTextColor (hdc);
BOOL TextOut (hdc, nXStart, nYStart, lpString, cbString);
.
, , , , ,
COLORREF SetBkColor (hdc, crColor);
COLORREF GetBkColor (hdc);
, ; CLR _ INVALID. SetBkColor .
int SetBkMode (hdc, iBkMode);
int GetBkMode (hdc);
, 0 ; int iBkMode , (OPAQUE) , ; TRANSPARENT , .
, , SetPixel GetPixel.
.
, , : , , ( ), ( OPAQUE) .
LineTo (hdc, xEnd, yEnd);
, , (xEnd, yEnd), . (0,0) LineTo , .
|
|
(xStart, yStart) (xEnd, yEnd) ()
MoveToEx (hdc, xStart, yStart, &pt);
pt POINT, . , LineTo (hdc, xEnd, yEnd); (xEnd, yEnd), , (xEnd, yEnd).
GetCurrentPositionEx (hdc, &pt);
100 , :
GetClientRect (hwnd, &rect); (. 1, WM _ PAINT);
for (x = 0; x < rect.right; x += 100) {
MoveToEx (hdc, x, 0, NULL);
LineTo (hdc, x, rect.bottom);
}
for (y = 0; y < rect.bottom; y += 100) {
MoveToEx (hdc, 0, y, NULL);
LineTo (hdc, rect.right, y);
}
pt cPoint,
Polyline (hdc, pt, cPoint);
, 5 (10 ), :
POINT pt [5] = { 100, 100, 200, 100, 200, 200, 100, 200, 100, 100 };
Polyline (hdc, pt, 5). , .
Polyline . PolylineTo .
MoveToEx (hdc, pt[0].x, pt[0].y, NULL);
PolylineTo (hdc, pt + 1, 4);
(. 6.2)
Arc (hdc, x1, y1, x2, y2, xStart, yStart, xEnd, yEnd);
(x 1, y 1) , (x 2, y 2) ; (xStart, yStart) ; (xEnd, yEnd) .
. 6.2. , Arc
,
PolyBezier (hdc, pt, iCount);
PolyBezierTo (hdc, pt, iCount);
pt POINT. PolyBezier : , , , . , .. iCount = 1+3* n , .