Figure 3: Using WM_CAPTURECHANGED instead of WM_CANCELMODE
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(); // complete the drag operation } return(0); case WM_CAPTURECHANGED: if (bDragging) { bDragging = FALSE; // clean up (e.g. free memory) } return(0);