Lock cursor, click away, click back, relock cursor?

So I have an app, and I lock the cursor in the start function, all is well. Then I alt tab away from the app, to use the mouse, then I click the app window again and the cursor is no longer locked.

Is there any “OnWindowFocus” function? Or do I just have to put Screem.lockCursor = true; into the update function?

checkout the FPS_Compelted tutorial, it has code for locking / unlocking that has worked for me.