剪裁输出
用户从菜单中单击“剪辑”后,应用程序将使用用户创建的矩形的坐标来定义剪裁区域。 定义剪辑区域并将其选入应用程序的设备上下文后,应用程序将重绘位图图像。 应用程序执行这些任务,如下所示。
// These variables are required for clipping.
static POINT ptUpperLeft;
static POINT ptLowerRight;
static POINT aptRect[5];
static POINT ptTmp;
static POINTS ptsTmp;
static BOOL fDefineRegion;
static BOOL fRegionExists;
static HRGN hrgn;
static RECT rctTmp;
int i;
case WM_COMMAND:
switch (wParam)
{
case IDM_CLIP:
hdc = GetDC(hwnd);
// Retrieve the application's client rectangle and paint
// with the default (white) brush.
GetClientRect(hwnd, &rctTmp);
FillRect(hdc, &rctTmp, GetStockObject(WHITE_BRUSH));
// Use the rect coordinates to define a clipping region.
hrgn = CreateRectRgn(aptRect[0].x, aptRect[0].y,
aptRect[2].x, aptRect[2].y);
SelectClipRgn(hdc, hrgn);
// Transfer (draw) the bitmap into the clipped rectangle.
BitBlt(hdc,
0, 0,
bmp.bmWidth, bmp.bmHeight,
hdcCompatible,
0, 0,
SRCCOPY);
ReleaseDC(hwnd, hdc);
break;
}