Thanks Jim, and I tried that; it was a bit more complicated as you needed to use the TrackMouseEvent API and it was awful to make work...
Though I found a better method eventually (using the SetCapture API); this one works perfectly and I love it

Here's the code, taken from my WndProc(), and slightly modified to be plugged into anyone else's (with minor changes):
// Variable definitions
RECT rect;
POINT point;
case WM_MOUSEMOVE:
GetClientRect(hWnd,&rect);
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
if(!PtInRect(&rect,point)) {
ReleaseCapture();
// Store mouse-in-window state and turn off mouse clicking states:
gui_setmouseinwindow(false);
gui_setmouseleftclicking(false);
gui_setmouserightclicking(false);
} else {
if(GetCapture() != hWnd) SetCapture(hWnd);
// Store the mouse-in-window state and mouse x and y coords:
gui_setmouseinwindow(true);
gui_setmousepos(LOWORD(lParam),HIWORD(lParam));
}
return 0;