📄 patterns.cpp
字号:
};
GetClientRect(hWnd, &rcClient);
nSide = rcClient.right / 6;
nXoffset = rcClient.right / 12;
nYoffset = 10;
lb.lbStyle = BS_HATCHED;
lb.lbColor = RGB(0x0, 0x0, 0x0);
rc[0].left = nXoffset;
rc[0].right = rc[0].left + nSide;
rc[0].top = nYoffset;
rc[0].bottom = rc[0].top + nSide;
rc[1].left = rc[0].left + rcClient.right / 3;
rc[1].right = rc[1].left + nSide;
rc[1].top = nYoffset;
rc[1].bottom = rc[1].top + nSide;
rc[2].left = rc[1].left + rcClient.right / 3;
rc[2].right = rc[2].left + nSide;
rc[2].top = nYoffset;
rc[2].bottom = rc[2].top + nSide;
rc[3].left = nXoffset;
rc[3].right = rc[3].left + nSide;
rc[3].top = nYoffset + rcClient.bottom / 2;
rc[3].bottom = rc[3].top + nSide;
rc[4].left = rc[3].left + rcClient.right / 3;
rc[4].right = rc[4].left + nSide;
rc[4].top = rc[3].top;
rc[4].bottom = rc[4].top + nSide;
rc[5].left = rc[1].left + rcClient.right / 3;
rc[5].right = rc[2].left + nSide;
rc[5].top = rc[3].top;
rc[5].bottom = rc[5].top + nSide;
CreateLogFont (hdc, lf);
HFONT hFont = CreateFontIndirect(&lf);
HPEN hPen = CreatePen (PS_SOLID, 1, RGB(0x0, 0x0, 0x0));
SelectObject (hdc, hPen);
SelectObject (hdc, hFont);
for (int i = 0; i < 6; ++i)
{
RECT rcText;
DrawShadow (hdc, rc[i]);
Rectangle (hdc, rc[i].left - 1,
rc[i].top - 1,
rc[i].right + 1,
rc[i].bottom + 1);
lb.lbHatch = lHatch[i];
HBRUSH hBrush = CreateBrushIndirect (&lb);
POINT point;
point.x = rc[i].left;
point.y = rc[i].top;
DPtoLP (hdc, &point, 1);
point.x %= 8;
point.y %= 8;
UnrealizeObject (hBrush);
SetBrushOrgEx (hdc, point.x, point.y, NULL);
SelectObject (hdc, hBrush);
FillRect (hdc, &rc[i], hBrush);
DeleteObject (hBrush);
rcText.left = rc[i].left - 10;
rcText.right = rc[i].right + 10;
rcText.top = rc[i].bottom + 6;
rcText.bottom = rcText.top + lf.lfHeight;
DrawText (hdc, szLabels[i], strlen (szLabels[i]),
&rcText, TEXT_FORMAT);
}
DeleteObject (hPen);
}
void DrawShadow (HDC hdc, RECT& rc)
{
RECT r = rc;
r.top += 4;
r.left += 4;
r.bottom += 4;
r.right += 4;
HBRUSH hBrush = CreateSolidBrush (RGB(0x77, 0x77, 0x77));
FillRect (hdc, &r, hBrush);
DeleteObject (hBrush);
}
void CreateLogFont (HDC hdc, LOGFONT & lf, int nPoints, char *szFace)
{
memset (&lf, '\0', sizeof (LOGFONT));
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfClipPrecision = OUT_TT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_ROMAN;
lf.lfHeight = MulDiv(nPoints, GetDeviceCaps(hdc, LOGPIXELSY), 72);
strcpy (lf.lfFaceName, szFace);
}
char *szBenDayText = " It was a rimy morning, and very damp. " \
"I had seen the damp lying on the outside of my little window, "\
"as if some goblin had been crying there all night, and "\
"using the window for a pocket-handkerchief. "\
"Now, I saw the damp lying on the bare hedges and spare grass, "\
"like a coarser sort of spiders' webs; hanging itself "\
"from twig to twig and blade to blade. On every rail and gate, "\
"wet lay clammy; and the marsh-mist was so thick, that the "\
"wooden finger on the post directing people to our village "\
"- a direction which they never accepted, for they never came "\
"there - was invisible to me until I was quite close under it. "\
"Then, as I looked up at it, while it dripped, it seemed to my "\
"oppressed conscience like a phantom devoting me to the Hulks.";
BOOL DrawBenDay (HWND hWnd, HDC hdc)
{
RECT rcClient, rcBenDay, rcText, rcShadow;
LOGFONT lf;
HFONT hFont;
CreateLogFont (hdc, lf, 12);
hFont = CreateFontIndirect(&lf);
SelectObject (hdc, hFont);
GetClientRect (hWnd, &rcClient);
rcText = rcClient;
rcText.top += 26;
rcText.bottom -= 26;
rcText.left = rcClient.right / 4 + 6;
rcText.right = 3 * rcClient.right / 4 - 6;
do
{
rcText.left -= 5;
if (rcText.left < 0)
{
MessageBox (hWnd, "Main window is too small", "BenDay", MB_OK);
return (FALSE);
}
rcText.right = rcClient.right - rcText.left - 6;
DrawText (hdc, szBenDayText, strlen (szBenDayText),
&rcText, DT_EDITCONTROL | DT_WORDBREAK | DT_CALCRECT);
} while ((rcText.bottom + 12) > rcClient.bottom);
rcBenDay = rcText;
rcBenDay.top -= 6;
rcBenDay.bottom += 6;
rcBenDay.left -= 6;
rcBenDay.right += 6;
rcShadow = rcBenDay;
rcShadow.top += 4;
rcShadow.bottom += 4;
rcShadow.left += 4;
rcShadow.right += 4;
HBRUSH hBrush = CreateSolidBrush (RGB(0x57, 0x57, 0x57));
FillRect (hdc, &rcShadow, hBrush);
DeleteObject (hBrush);
Rectangle (hdc, rcBenDay.left - 1,
rcBenDay.top - 1,
rcBenDay.right + 1,
rcBenDay.bottom + 1);
hBrush = CreateSolidBrush (RGB(0xcf, 0xcf, 0xcf));
FillRect (hdc, &rcBenDay, hBrush);
DeleteObject (hBrush);
// CreateLogFont (hdc, lf, 14);
SetBkMode (hdc, TRANSPARENT);
DrawText (hdc, szBenDayText, strlen (szBenDayText),
&rcText, DT_EDITCONTROL | DT_WORDBREAK);
return (TRUE);
}
void DrawJoins (HWND hWnd, HDC hdc)
{
RECT rc[3];
RECT rcClient;
int nXoffset, nYoffset;
LOGBRUSH lb;
LOGFONT lf;
HPEN hPen;
HFONT hFont;
DWORD dwJoin[] = {PS_JOIN_BEVEL, PS_JOIN_MITER, PS_JOIN_ROUND};
char *szLabels[] =
{
"PS_JOIN_BEVEL",
"PS_JOIN_MITER",
"PS_JOIN_ROUND"
};
CreateLogFont (hdc, lf, 14);
hFont = CreateFontIndirect(&lf);
GetClientRect (hWnd, &rcClient);
nXoffset = 12;
nYoffset = 12;
rc[0].top = rcClient.top + nYoffset;
rc[0].bottom = (rcClient.bottom - 2 * nYoffset) / 3;
rc[0].left = rcClient.left + nXoffset;
rc[0].right = rcClient.right - nXoffset;
rc[1].top = rc[0].bottom + nYoffset;
rc[1].bottom = rc[1].top + rc[0].bottom - rc[0].top;
rc[1].left = rc[0].left;
rc[1].right = rc[0].right;
rc[2].top = rc[1].bottom + nYoffset;
rc[2].bottom = rc[2].top + rc[1].bottom - rc[1].top;
rc[2].left = rc[1].left;
rc[2].right = rc[1].right;
// int nStep = (rc[0].right - rc[0].left) / (2 * 3);
// int nStart = (rc[0].right - rc[0].left) / 6 + nXoffset;
int nStart = (rc[0].right - rc[0].left) / 6 + 4 * nXoffset;
int nStep = (rc[0].right - nStart) / 5;
//
// Uncomment the following lines to produce a lightly shaded
// backbround for aligning the image.
// HBRUSH hBrush = CreateSolidBrush (RGB(0xf7, 0xf7, 0xf7));
// FillRect (hdc, &rc[0], hBrush);
// FillRect (hdc, &rc[1], hBrush);
// FillRect (hdc, &rc[2], hBrush);
// DeleteObject (hBrush);
lb.lbColor = (RGB(0x00, 0x00, 0x00));
lb.lbStyle = BS_SOLID;
lb.lbHatch = 0;
RECT rcText;
rcText.left = rc[0].left + 6;
rcText.right = rc[0].right;
int nTypeHigh = lf.lfHeight < 0 ? lf.lfHeight : -lf.lfHeight;
SetBkMode (hdc, TRANSPARENT);
for (int i = 0; i < 3; ++i)
{
hPen = ExtCreatePen (PS_GEOMETRIC | PS_ENDCAP_FLAT | dwJoin[i] | PS_SOLID, 10,
&lb, 0, NULL);
SelectObject (hdc, hPen);
BeginPath (hdc);
MoveToEx (hdc, nStart, rc[i].bottom - 5, NULL);
for (int j = 0; j < 5; ++j)
{
LineTo (hdc, nStart + nStep * (j + 1) - 5,
j % 2 ? rc[i].bottom - 5 : rc[i].top + 5);
}
// CloseFigure (hdc);
EndPath (hdc);
StrokePath (hdc);
SelectObject (hdc, hFont);
DeleteObject (hPen);
rcText.top = rc[i].top + (rc[i].bottom - rc[i].top + nTypeHigh) / 2;
rcText.bottom = rcText.top + nTypeHigh;
DrawText (hdc, szLabels[i], strlen (szLabels[i]),
&rcText, TEXT_FORMAT & ~DT_CENTER);
}
DeleteObject (hFont);
}
void DrawEndCaps (HWND hWnd, HDC hdc)
{
RECT rc[3];
RECT rcClient;
int nXoffset, nYoffset;
LOGBRUSH lb;
LOGFONT lf;
HPEN hPen;
HFONT hFont;
DWORD lEndCap[] = {PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE, PS_ENDCAP_FLAT};
char *szLabels[] =
{
"PS_ENDCAP_ROUND",
"PS_ENDCAP_SQUARE",
"PS_ENDCAP_FLAT"
};
CreateLogFont (hdc, lf, 14);
hFont = CreateFontIndirect(&lf);
SelectObject (hdc, hFont);
GetClientRect (hWnd, &rcClient);
nXoffset = 12;
nYoffset = 12;
rc[0].top = rcClient.top + nYoffset;
rc[0].bottom = (rcClient.bottom - 2 * nYoffset) / 3;
rc[0].left = rcClient.left + nXoffset;
rc[0].right = rcClient.right - nXoffset;
rc[1].top = rc[0].bottom + nYoffset;
rc[1].bottom = rc[1].top + rc[0].bottom - rc[0].top;
rc[1].left = rc[0].left;
rc[1].right = rc[0].right;
rc[2].top = rc[1].bottom + nYoffset;
rc[2].bottom = rc[2].top + rc[1].bottom - rc[1].top;
rc[2].left = rc[1].left;
rc[2].right = rc[1].right;
int nStart = (rc[0].right - rc[0].left) / 6 + 4 * nXoffset;
int nStep = (rc[0].right - nStart) / 5;
//
// Uncomment the following lines to produce a lightly shaded
// backbround for aligning the image.
// HBRUSH hBrush = CreateSolidBrush (RGB(0xf7, 0xf7, 0xf7));
// FillRect (hdc, &rc[0], hBrush);
// FillRect (hdc, &rc[1], hBrush);
// FillRect (hdc, &rc[2], hBrush);
// DeleteObject (hBrush);
lb.lbColor = (RGB(0x00, 0x00, 0x00));
lb.lbStyle = BS_SOLID;
lb.lbHatch = 0;
RECT rcText;
rcText.left = rc[0].left + 6;
rcText.right = rc[0].right;
int nTypeHigh = lf.lfHeight < 0 ? lf.lfHeight : -lf.lfHeight;
SetBkMode (hdc, TRANSPARENT);
for (int i = 0; i < 3; ++i)
{
hPen = ExtCreatePen (PS_GEOMETRIC | lEndCap[i] | PS_SOLID, 10,
&lb, 0, NULL);
SelectObject (hdc, hPen);
MoveToEx (hdc, nStart, rc[i].bottom - 5, NULL);
for (int j = 0; j < 5; ++j)
{
LineTo (hdc, nStart + nStep * (j + 1),
j % 2 ? rc[i].bottom - 5 : rc[i].top + 5);
}
DeleteObject (hPen);
rcText.top = rc[i].top + (rc[i].bottom - rc[i].top + nTypeHigh) / 2;
rcText.bottom = rcText.top + nTypeHigh;
DrawText (hdc, szLabels[i], strlen (szLabels[i]),
&rcText, TEXT_FORMAT & ~DT_CENTER);
}
DeleteObject (hFont);
}
void DoBitBlast (HWND hWnd, HDC hdc)
{
HBITMAP hBmp;
RECT rc;
HDC BmpDC;
GetClientRect(hWnd, &rc);
hBmp = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DUDLEY));
// hBmp = (HBITMAP) LoadImage (hInst, MAKEINTRESOURCE (IDB_DUDLEY), IMAGE_BITMAP,
// rc.right, rc.bottom, LR_DEFAULTCOLOR);
BmpDC = CreateCompatibleDC(hdc);
SelectObject (BmpDC, hBmp);
BitBlt (hdc, 0, 0, rc.right, rc.bottom,
BmpDC, 0, 0, SRCCOPY);
DeleteObject (hBmp);
DeleteDC (BmpDC);
}
void DoBitStretch (HWND hWnd, HDC hdc)
{
HBITMAP hBmp;
RECT rc;
HDC BmpDC;
GetClientRect(hWnd, &rc);
// hBmp = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DUDLEY));
hBmp = (HBITMAP) LoadImage (hInst, MAKEINTRESOURCE (IDB_DUDLEY), IMAGE_BITMAP,
rc.right, rc.bottom, LR_DEFAULTCOLOR);
BmpDC = CreateCompatibleDC(hdc);
SelectObject (BmpDC, hBmp);
BitBlt (hdc, 0, 0, rc.right, rc.bottom,
BmpDC, 0, 0, SRCCOPY);
// StretchBlt(hdc, 0, 0, rc.right, rc.bottom, BmpDC,
// 0, 0, 320, 274, SRCCOPY);
DeleteObject (hBmp);
DeleteDC (BmpDC);
}
void DoLoadBitmapFromFile (HWND hWnd, HDC hdc)
{
HBITMAP hBmp;
RECT rc;
HDC BmpDC;
OPENFILENAME ofn;
char strFileName[_MAX_PATH];
memset (&ofn, '\0', sizeof (OPENFILENAME));
memset (strFileName, '\0', sizeof (strFileName));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hWnd;
// ofn.hInstance = hInst;
ofn.lpstrFile = strFileName;
ofn.lpstrTitle = "Open Bitmap";
ofn.nMaxFile = _MAX_PATH;
ofn.nMaxFileTitle = _MAX_PATH;
ofn.lpstrDefExt = _T(".bmp");
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT;
ofn.lpstrFilter = _T("Bitmap files (*.bmp)\0*.bmp\0\0");
int nResult = GetSaveFileName (&ofn);
if ((nResult == 0) || (nResult == IDCANCEL))
return;
if (!exist (ofn.lpstrFile))
return;
GetClientRect(hWnd, &rc);
hBmp = (HBITMAP) LoadImage (NULL, ofn.lpstrFile, IMAGE_BITMAP,
rc.right, rc.bottom, LR_DEFAULTCOLOR | LR_LOADFROMFILE);
BmpDC = CreateCompatibleDC(hdc);
SelectObject (BmpDC, hBmp);
BitBlt (hdc, 0, 0, rc.right, rc.bottom,
BmpDC, 0, 0, SRCCOPY);
// StretchBlt(hdc, 0, 0, rc.right, rc.bottom, BmpDC,
// 0, 0, 320, 274, SRCCOPY);
DeleteObject (hBmp);
DeleteDC (BmpDC);
}
bool exist (const char *path)
{
return (exist ((char *) path));
}
bool exist (char *path)
{
return _access (path, 4) ? false : true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -