So that the user can select a rectangle in which to copy the current bitmap,
you must add WM_LBUTTONUP, WM_MOUSEMOVE, and WM_LBUTTONDOWN cases to your application's window procedure.
These cases use the selection functions (described in Chapter 20, “Dynamic-Link Libraries”) to create a selection rectangle and supply feedback to the user. The WM_LBUTTONUP case then uses the StretchBlt function to fill the rectangle. To create these cases, add the following statements to your window procedure:
case WM_LBUTTONDOWN:
fTrack = TRUE;
SetRectEmpty(&Rect);
StartSelection(hwnd, MAKEPOINT(lParam), &Rect,
(wParam & MK_SHIFT) ? (SL_EXTEND | fwShape) : fwShape);
break;
case WM_MOUSEMOVE:
if (fTrack)
UpdateSelection(hwnd, MAKEPOINT(lParam), &Rect,
fwShape);
break;
case WM_LBUTTONUP:
fTrack = FALSE;
EndSelection(MAKEPOINT(lParam), &Rect);
ClearSelection(hwnd, &Rect, fwShape);
hdc = GetDC(hwnd);
SetStretchBltMode(hdc, fwStretchMode);
StretchBlt(hdc, Rect.left, Rect.top,
Rect.right - Rect.left, Rect.bottom - Rect.top,
hdcMemory, 0, 0,
Bitmap.bmWidth, Bitmap.bmHeight,
SRCCOPY);
ReleaseDC(hwnd, hdc);
break;
To use these functions, you also must include the SELECT.H file (defined in Chapter 20, “Dynamic-Link Libraries”), by adding the following statement to the beginning of your source file:
#include "select.h"