Alguien sabe alguna forma fácil de hacer que el ratón no pueda salir de los límites de un diálogo. Supongo que deberá utilizarse SetCapture() pero no he conseguido implementar nada que funciona.
Gracias
Rafael
Alguien sabe alguna forma fácil de hacer que el ratón no pueda salir de los límites de un diálogo. Supongo que deberá utilizarse SetCapture() pero no he conseguido implementar nada que funciona.
Gracias
Rafael
Rafael,
En MsDos se podía hacer, pero en Windows creo que no existe la opción de restringir el movimiento del ratón a un área específica.
IF r <= 0
MoverCursorA(0,c)
ENDIF
IF c <= 0
MoverCursorA(r,0)
ENDIFRafael,
Sí existe la función ![]()
The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area.
BOOL ClipCursor(
CONST RECT *lpRect // pointer to structure with rectangle
);
Parameters
lprc
Points to the RECT structure that contains the screen coordinates of the upper-left and lower-right corners of the confining rectangle. If this parameter is NULL, the cursor is free to move anywhere on the screen.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The cursor is a shared resource. If an application confines the cursor, it must release the cursor by using ClipCursor before relinquishing control to another application.
#include "fivewin.ch"
*************
function MAIN
*************
local oDlg
define dialog oDlg from 0, 0 to 400, 600 pixel
* Posiciona o cursor do mouse
@10, 10 button "Posicionar" of oDlg action setcursorpos( 200, 300 ) pixel
* Mostra o Mouse na Tela
@30, 10 button "Mostar" of oDlg action SHOW_MOUSE() pixel
* Esconde o Mouse nesta Dialog
@50, 10 button "Esconder" of oDlg action HIDE_MOUSE() pixel
* Confina o Mouse em uma certa posicao da tela
@70, 10 button "Confinar" of oDlg action clipcursor( 10, 10, 10, 10 ) pixel
* Confina o Mouse em uma certa posicao da tela
@90, 10 button "Sair Confinamento" of oDlg ;
action ( clipcursor( 0, 0, 800, 600 ), setcursorpos( 400, 300 ) ) pixel
activate dialog oDlg centered
return NIL
*******************
function HIDE_MOUSE
*******************
local ST_CUR
do while .T.
ST_CUR := ShowCursor( 0 )
if ST_CUR < 0 && Enquanto o Status do ponteiro nao for Menor que Zero
exit
endif
enddo
return NIL
*******************
function SHOW_MOUSE
*******************
local ST_CUR
do while .T.
ST_CUR := ShowCursor( 1 )
if ST_CUR >= 0 && Enquanto o Status do ponteiro for Maior ou igual a Zero
exit
endif
enddo
return NIL
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
HB_FUNC( CLIPCURSOR )
{
RECT rct;
rct.left = hb_parnl( 1 );
rct.top = hb_parnl( 2 );
rct.right = hb_parnl( 3 );
rct.bottom = hb_parnl( 4 );
hb_retl( ClipCursor( &rct ) );
}
#pragma ENDDUMPRossine, Antonio:
¡Estupendo! Muchísimas gracias a los dos
Rafael