c++windowswindowed

Is there any way in C++ windows code to stop a mouse moving oustide window bounds


I had a look and couldn't find any way apart from 3rd party programs. But is there any way through code (C++) that I can stop the cursor from being moved outside the bounds of the window? I have a FPS Game project on windows but obviously in windowed mode the mouce can be moved outside of the window which can then cause issues.


Solution

  • Try ClipCursor:

    CRect rect;
    GetWindowRect(&rect);
    ClipCursor(&rect);
    

    Remember to release che Cursor with ClipCursor(NULL);