This is a rather simple but effective way to keep a window from being dragged out of the screen area.
Add this piece of code to your window/dialog procedure:
long scrx, scry;
RECT * rect;
rect = (RECT *)lParam;
scrx = GetSystemMetrics(SM_CXSCREEN);
scry = GetSystemMetrics(SM_CYSCREEN);
if(rect->right > scrx)
OffsetRect(rect, scrx - rect->right, 0);
if(rect->bottom > scry)
OffsetRect(rect, 0, scry - rect->bottom);
if(rect->left < 0)
OffsetRect(rect, -rect->left, 0);
if(rect->top < 0)
OffsetRect(rect, 0, -rect->top);
Just thought it might be useful to someone...