Lock the mouse within the window

how do I allow the mouse to be visible, but stuck within the bounds of the window? and on a similar note, how do i give the mouse a custom pointer?