Figure 2: Using WM_CANCELMODE to avoid problems
case WM_LBUTTONDOWN: SetCapture(hwnd); bDragging = TRUE; // perform initializations (e.g. allocate memory) return(0); case WM_MOUSEMOVE: if (bDragging) DoDragStuff(); return(0); case WM_LBUTTONUP: if (bDragging) { ReleaseCapture(); bDragging = FALSE; // complete the drag operation // clean up (e.g. free memory) } return(0); case WM_CANCELMODE: if (bDragging) { bDragging = FALSE; // cancel the drag operation // clean up (e.g. free memory) } return(DefWindowProc(hwnd, uMsg, wParam, lParam));