so far i got the following code, wich is already working pretty good. my only problem right now are to get the border values around the engine window. this can be different from system to system. so one user might have a real big border around every window - so this border will be around the gamestudio engine window too.
right now i try to get the correct values with
caption_size = sys_metrics(4)+sys_metrics(7); //SM_CYCAPTION
border_size = sys_metrics(7);
because i assume the title + border size forms the top window, then i just add +1 to make shure its really inside.
this seems to work for me but i'm not shure if this is correct. you have to constantly run mouse_checkTrap() in a loop to handle alt+tab losing focus of the engine window and you have to use mouse_setTrap() everytime you switch the resolution and mouse_freeTrap() once you exit the engine to make shure the mouse is set free again.
did i forgot something? is this the correct way of getting the borders?
Code:
//-----------------
// traps the mouse inside engine window
//-----------------
void mouse_setTrap()
{
RECT rc_clip;
short caption_size;
short border_size;
caption_size = sys_metrics(4)+sys_metrics(7); //SM_CYCAPTION
border_size = sys_metrics(7);
// lets set a rectangle with the correct size depending on what the user desktop settings are
// so the mouse gets trapped in the engine window even if he has some fancy windows theme
rc_clip.top = window_pos.y+caption_size+1;
rc_clip.left = window_pos.x+border_size+1;
rc_clip.right = window_pos.x+screen_size.x+border_size;
rc_clip.bottom = window_pos.y+screen_size.y+caption_size;
ClipCursor(&rc_clip);
}
//-----------------
// set me free
//-----------------
void mouse_freeTrap()
{
ClipCursor(NULL);
}
//-----------------
// watch mouse trap in a loop somewhere to release the trap if engine lost focus
//-----------------
void mouse_checkTrap()
{
if(!window_focus)
{
if(mouse_isTrapped)
{
mouse_isTrapped=FALSE;
mouse_freeTrap();
}
}
else
{
if(!mouse_isTrapped)
{
mouse_isTrapped=TRUE;
mouse_setTrap();
}
}