Your function worked perfect.
This was an API and need one _ at the end. It took little time to realize that.
I will tell my technique.
When the game starts , after loading graphics and initialize everything put this:
game_window=GetForegroundWindow_()
You must declare one Global integer variable as game_window.i
And in your main game loop you need to have one Procedure with the name mouse_trap().
You will call this procedure always in your gameloop.
The code of the Mouse_trap procedure:
Procedure Mouse_trap()
game_active_window=GetForegroundWindow_()
If game_window=game_active_window
If Pointer_x>=639: dbPositionMouse(638,Pointer_y):EndIf
If Pointer_x<0: dbPositionMouse(1,Pointer_y):EndIf
If Pointer_y>=479: dbPositionMouse(Pointer_x,478):EndIf
If Pointer_y<0: dbPositionMouse(Pointer_x,1):EndIf
EndIf
EndProcedure
The mouse_trap procedure checks another one Global variable as integer with name game_active_window.i
This is the current variable before checking for the mouse trap.
If you are in your game window , the game_active_window variable always refreshes , but the game_window variable was initialized once at the beginning.
If the current game_active_window variable is equals with the beginning variable which not changes , you are in current window and the mouse_trap routine runs , else these variables are not equal
and the mouse_trap routine is not running and the mouse is not trapped when your game is running in the background.
Mistrel you are THE BEST. Thank you.
The above example was for 640x480 resolution. You can replace the numbers above with dbscreenwidth() and dbscreenheight() functions.
Procedure Mouse_trap()
game_active_window=GetForegroundWindow_()
If game_window=game_active_window
If Pointer_x>=dbscreenwidth()-1: dbPositionMouse(dbscreenwidth()-2,Pointer_y):EndIf
If Pointer_x<0: dbPositionMouse(1,Pointer_y):EndIf
If Pointer_y>=dbscreenheight()-1: dbPositionMouse(Pointer_x,dbscreenheight()-2):EndIf
If Pointer_y<0: dbPositionMouse(Pointer_x,1):EndIf
EndIf
EndProcedure
And your code will run in any resolution you want.
Pointer_x and Pointer_y are another integer variables which are global too.
And you need to put this code in your game loop to update your mouse position and put it in these variables.
Pointer_x=dbMouseX()
Pointer_y=dbMouseY()
Pointer_b=dbMouseclick()
These techniques worked to me and I used them in my games.
Have a nice day.