Capturar ratón sobre un diálogo

Capturar ratón sobre un diálogo

Postby Rafael Clemente » Fri Mar 24, 2006 7:55 pm

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
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Postby Antonio Linares » Sat Mar 25, 2006 8:08 am

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41476
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rafael Clemente » Sat Mar 25, 2006 11:26 am

Antonio:
¿Hay alguna función que permita mover el cursor a una posición determinada (he probado MouseTo() pero no me resuelve el problema)

Si fuera así, supongo que sería tan fácil como en bMMove hacer algo así:
Code: Select all  Expand view
IF r <= 0
   MoverCursorA(0,c)
ENDIF
IF c <= 0
   MoverCursorA(r,0)
ENDIF

y así para los cuatro lados del diálogo.

Otra solución quizás podría ser utilizar la funcion ClipCursor(aRect) del API de Windows, pero la verdad es que no sé como llamarla. Me puedes dar un ejemplo, por favor?
Rafael
[/code]
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Postby Antonio Linares » Sat Mar 25, 2006 12:41 pm

Rafael,

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41476
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rossine » Sat Mar 25, 2006 3:00 pm

Olá Rafael,

Compile e teste este exemplo.

Code: Select all  Expand view
#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 ENDDUMP



Saludos,

Rossine.
Rossine
 
Posts: 344
Joined: Tue Oct 11, 2005 11:33 am

Postby Rafael Clemente » Sat Mar 25, 2006 7:36 pm

Rossine, Antonio:

¡Estupendo! Muchísimas gracias a los dos

Rafael
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 31 guests