Add WM_LBUTTONUP, WM_MOUSEMOVE, and WM_LBUTTONDOWN Cases

You need to add WM_LBUTTONUP, WM_MOUSEMOVE, and WM_LBUTTONDOWN cases to the window function to let the user select a rectangle in which to copy the current bitmap. These cases use the selection functions to create a selection rectangle and supply feedback to the user. For information on the selection functions, see “A Sample Library: Select” on page 550. The WM_LBUTTONUP case then uses the StretchBlt function to fill the rectangle. Add the following statements to your window function:

case WM_LBUTTONDOWN: /* message: left mouse button pressed */

bTrack = TRUE;

SetRectEmpty((LPRECT) &Rect);

StartSelection(hWnd, MAKEPOINT(lParam), (LPRECT) &Rect,

(wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);

break;

case WM_MOUSEMOVE: /* message: mouse movement */

if (bTrack)

UpdateSelection(hWnd, MAKEPOINT(lParam), (LPRECT) &Rect, Shape);

break;

case WM_LBUTTONUP: /* message: left mouse button released */

bTrack = FALSE;

EndSelection(MAKEPOINT(lParam), (LPRECT) &Rect);

ClearSelection(hWnd, (LPRECT) &Rect, Shape);

hDC = GetDC(hWnd);

SetStretchBltMode(hDC, fStretchMode);

StretchBlt(hDC, Rect.left, Rect.top,

Rect.right - Rect.left, Rect.bottom - Rect.top,

hMemoryDC, 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 28, “Dynamic-Link Libraries”). Add the following statement to the beginning of your source file:

#include “SELECT.H”