void Draw9(
HDC hDC, // 目标DC
const CRect& rcDraw, // 要绘制的区域
Image * pImage, // 加载了图片资源的Image对象
const CRect& rcRes1, // 资源左上角区域
const CRect& rcRes2 // 资源右下角区域
)
{
Graphics graph(hDC);
RectF rcf1(rcDraw.left, rcDraw.top, rcRes1.Width(), rcRes2.Height());
RectF rcf2(rcDraw.left+rcRes1.Width(), rcDraw.top, rcDraw.Width()-rcRes1.Width()-rcRes2.Width(), rcRes1.Height());
RectF rcf3(rcDraw.Width()-rcRes2.Width()+rcDraw.left, rcDraw.top, rcRes2.Width(), rcRes1.Height());
RectF rcf4(rcDraw.left, rcDraw.top+rcRes1.Height(), rcRes1.Width(), rcDraw.Height()-rcRes1.Height()-rcRes2.Height());
RectF rcf5(rcDraw.left+rcRes1.Width(), rcDraw.top+rcRes1.Height(), rcDraw.Width()-rcRes1.Width()-rcRes2.Width(), rcDraw.Height()-rcRes1.Height()-rcRes2.Height());
RectF rcf6(rcDraw.Width()-rcRes2.Width()+rcDraw.left, rcDraw.top+rcRes1.Height(), rcRes2.Width(), rcDraw.Height()-rcRes1.Height()-rcRes2.Height());
RectF rcf7(rcDraw.left, rcDraw.Height()-rcRes2.Height()+rcDraw.top, rcRes1.Width(), rcRes2.Height());
RectF rcf8(rcDraw.left+rcRes1.Width(), rcDraw.Height()-rcRes2.Height()+rcDraw.top, rcDraw.Width()-rcRes1.Width()-rcRes2.Width(), rcRes2.Height());
RectF rcf9(rcDraw.Width()-rcRes2.Width()+rcDraw.left, rcDraw.Height()-rcRes2.Height()+rcDraw.top, rcRes2.Width(), rcRes2.Height());
graph.DrawImage(pImage, rcf1, rcRes1.left, rcRes1.top, rcRes1.Width(), rcRes1.Height(), UnitPixel);
graph.DrawImage(pImage, rcf2, rcRes1.right+1, rcRes1.top, 1, rcRes1.Height(), UnitPixel);
graph.DrawImage(pImage, rcf3, rcRes2.left, rcRes1.top, rcRes2.Width(), rcRes1.Height(), UnitPixel);
graph.DrawImage(pImage, rcf4, rcRes1.left, rcRes1.bottom+1, rcRes1.Width(), 1, UnitPixel);
graph.DrawImage(pImage, rcf5, rcRes1.right+1, rcRes1.bottom+1, 1, 1, UnitPixel);
graph.DrawImage(pImage, rcf6, rcRes2.left, rcRes1.bottom+1, rcRes2.Width(), 1, UnitPixel);
graph.DrawImage(pImage, rcf7, rcRes1.left, rcRes2.top, rcRes1.Width(), rcRes2.Height(), UnitPixel);
graph.DrawImage(pImage, rcf8, rcRes1.right+1, rcRes2.top, 1, rcRes2.Height(), UnitPixel);
graph.DrawImage(pImage, rcf9, rcRes2.left, rcRes2.top, rcRes2.Width(), rcRes2.Height(), UnitPixel);
graph.ReleaseHDC(hDC);
}
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap memBmp, * pmemBmp;
memBmp.CreateCompatibleBitmap(&dc, rcWnd.Width(), rcWnd.Height());
pmemBmp = memDC.SelectObject(&memBmp);
memDC.FillSolidRect(rcWnd, 0xFFFF00);
CRect rcDraw = rcWnd;
Draw9(memDC.m_hDC, rcDraw, m_pImage, CRect(45,66,54,76), CRect(58,80,67,90));
dc.BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pmemBmp);
ReleaseDC(&memDC);