void _Rectangle(HDC hdc, int x1, int y1, int x2, int y2, COLORREF crPen, COLORREF crBrush) {
HBRUSH newBrush, oldBrush;
HPEN newPen, oldPen;
// 브러쉬 모양 (Solid, Hatch)
int nRandBrush = rand() % 2;
if (g_nWidth && g_nHeight) {
//newBrush = CreateSolidBrush(crBrush);
if (nRandBrush) {
newBrush = CreateSolidBrush(_RandColor());
}
else {
// HatchBrush 모양 총 6개
newBrush = CreateHatchBrush(rand() % 6, _RandColor());
}
oldBrush = (HBRUSH)SelectObject(hdc, newBrush);
newPen = CreatePen(rand() % 7, _FontWidth(), crPen);
oldPen = (HPEN)SelectObject(hdc, newPen);
Rectangle(hdc, x1, y1, x2, y2);
SelectObject(hdc, oldBrush);
DeleteObject(newBrush);
SelectObject(hdc, oldPen);
DeleteObject(newPen);
}
}
void _Line(HDC hdc, int x1, int y1, int x2, int y2, COLORREF crPen) {
HBRUSH newBrush, oldBrush;
if (g_nWidth && g_nHeight) {
newBrush = CreateSolidBrush(crPen);
oldBrush = (HBRUSH)SelectObject(hdc, newBrush);
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
SelectObject(hdc, oldBrush);
DeleteObject(newBrush);
}
}
void _Ellipse(HDC hdc, int x1, int y1, int x2, int y2, COLORREF crPen, COLORREF crBrush) {
HBRUSH newBrush, oldBrush;
HPEN newPen, oldPen;
if (g_nWidth && g_nHeight) {
newBrush = CreateSolidBrush(crBrush);
oldBrush = (HBRUSH)SelectObject(hdc, newBrush);
newPen = CreatePen(rand() % 7, _FontWidth(), crPen);
oldPen = (HPEN)SelectObject(hdc, newPen);
Ellipse(hdc, x1, y1, x2, y2);
SelectObject(hdc, oldBrush);
DeleteObject(newBrush);
SelectObject(hdc, oldPen);
DeleteObject(newPen);
}
}
void _CrossLine(HDC hdc, int x1, int y1, int x2, int y2) {
HPEN newPen, oldPen;
newPen = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
oldPen = (HPEN)SelectObject(hdc, newPen);
if (g_nWidth && g_nHeight) {
_Line(hdc,
x1 + (x2 - x1) / 2,
y1,
x1 + (x2 - x1) / 2,
y2, RGB(0, 0, 0));
_Line(hdc,
x1,
y1 + (y2 - y1) / 2,
x2,
y1 + (y2 - y1) / 2, RGB(0, 0, 0));
}
SelectObject(hdc, oldPen);
DeleteObject(newPen);
}
void _RandRect(HDC hdc, int nClientWidth, int nClientHeight) {
HBRUSH newBrush, oldBrush;
HPEN newPen, oldPen;
// 브러쉬 모양 (Solid, Hatch)
int nRandBrush = rand() % 2;
// 도형 모양 (Rectangle, RoundRectangle, Ellipse)
int nRandFunc = rand() % 3;
// 랜덤 Brush색
if (g_nWidth && g_nHeight) {
if (nRandBrush) {
newBrush = CreateSolidBrush(_RandColor());
}
else {
// HatchBrush 모양 총 6개
newBrush = CreateHatchBrush(rand() % 6, _RandColor());
}
oldBrush = (HBRUSH)SelectObject(hdc, newBrush);
newPen = CreatePen(rand() % 7, _FontWidth(), _RandColor());
oldPen = (HPEN)SelectObject(hdc, newPen);
switch (nRandFunc) {
case 0:
// 사각형
_Rectangle(hdc, rand() % nClientWidth,
rand() % nClientHeight,
rand() % nClientWidth,
rand() % nClientHeight,
_RandColor(), _RandColor());
break;
case 1:
// 모서리 둥근 사각형
RoundRect(hdc, rand() % nClientWidth,
rand() % nClientHeight,
rand() % nClientWidth,
rand() % nClientHeight,
rand() % 3,
rand() % 3);
break;
case 2:
// 원
_Ellipse(hdc, rand() % nClientWidth,
rand() % nClientHeight,
rand() % nClientWidth,
rand() % nClientHeight,
_RandColor(), _RandColor());
break;
}
SelectObject(hdc, oldBrush);
DeleteObject(newBrush);
SelectObject(hdc, oldPen);
DeleteObject(newPen);
}
}
전체 글
- [API] Rectangle, Ellipse, LineTo 2021.02.18
[API] Rectangle, Ellipse, LineTo
2021. 2. 18. 23:46