You cannot and - more importantly - SHOULD not restrict the mouse movement to a certain window. If the player is choosing windowed mode he does so for a reason and you'd take just this reason away with the restriction.
To your problem: on every mouse click check if the mouse is within the bounds of the window. If it is not just ignore the click. You can use
http://www.conitec.net/beta/amouse_valid.htm for this purpose.