FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Regres贸 el foco a esta ventana?
Posts: 257
Joined: Tue May 16, 2006 04:46 PM
Regres贸 el foco a esta ventana?
Posted: Thu Mar 01, 2012 02:39 AM

Hola foro,

Desde el menu principal abro una ventana con la "FuncionA()", posteriormente tambien desde el menu principal abro una nueva completamente diferente desde , con la "FuncionB()". Como puedo saber desde la "FuncionA()" que di clic nuevamente en la 1er ventana para ponerla nuevamente en foco?

RodolfoRBG
FWH 1307, xHarbour123 BCC582
rodolfoerbg@gmail.com
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 12:14 AM

Prueba con

oWnd1:Restore()
oWnd1:SetFocus()

Dios no est谩 muerto...



Gracias a mi Dios ante todo!
Posts: 257
Joined: Tue May 16, 2006 04:46 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 01:10 AM

Gracias Jose Luis, pero donde lo pondria? en ON INIT? en VALID? o en que parte esta monitoreando cuando se pasa el foco a la ventana?

RodolfoRBG
FWH 1307, xHarbour123 BCC582
rodolfoerbg@gmail.com
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 01:49 PM
Rodolfo;
Te dejo este c贸digo, que entiendo es lo que necesitas, y que Manu Exp贸sito me lo cedi贸 hace unos cuaaaaantos a帽os :-)

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
// 聽DATAS.....: * lCapture tiene un valor logico, .f. si la ventana no se 聽 聽 //
// 聽 聽 聽 聽 聽 聽 聽pudo capturar y .t. si si se hizo 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 //
// 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽//
// 聽METODOS...: * New( cTitle ) es el constructor, cTitle es el titulo de una //
// 聽 聽 聽 聽 聽 聽 聽ventana, si se le pasa intentara capturarla y pondra .t. en 聽 //
// 聽 聽 聽 聽 聽 聽 聽::lCapture 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽//
// 聽 聽 聽 聽 聽 聽 聽* WCapture se encarga de buscar la ventana y asignarla a 聽 聽 聽//
// 聽 聽 聽 聽 聽 聽 聽nuestro objeto TWindow. Si la captura podremos interactuar 聽 聽//
// 聽 聽 聽 聽 聽 聽 聽como si fuera una ventana mas de nuestra aplicacion 聽 聽 聽 聽 聽 //
// 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽//
// 聽NOTAS.....: TWCapture esta heredada de TWindows por lo que tendremos a 聽 聽//
// 聽 聽 聽 聽 聽 聽 聽nuestra disposicion todas las datas y metodos de esta clase. 聽//
// 聽 聽 聽 聽 聽 聽 聽No distingue entre mayusculas y minuscula pero si se tienen 聽 //
// 聽 聽 聽 聽 聽 聽 聽en cuenta los espacios 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽//
//----------------------------------------------------------------------------//

#include "Objects.ch"

//----------------------------------------------------------------------------//

CLASS TWCapture FROM TWindow

聽 聽 DATA lCaptured 聽AS BOOL

聽 聽 METHOD New( cTitle ) CONSTRUCTOR
聽 聽 METHOD WCapture( cTitle )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cTitle ) CLASS TWCapture

聽 聽 if( ValType( cTitle ) == "C", ::WCapture( cTitle ), ::lCaptured := .f. )

return( Self )

//----------------------------------------------------------------------------//

METHOD WCapture( cTitle ) CLASS TWCapture

聽 聽local hWnd := FindWindow( 0, cTitle )

聽 聽::lCaptured := ( hWnd > 0 )
聽 聽::hWnd := if( ::lCaptured, hWnd, 0 )

return( ::lCaptured )

//----------------------------------------------------------------------------//


Sample01
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
// TWCapture by Manu Exposito
// Demo01 de la clase TWCapture
// Pasando un titulo de ventana
//----------------------------------------------------------------------------//

#define CRLF chr( 13 ) + chr( 10 )

function Main()

聽 聽local oWnd
聽 聽local cTitle := space( 40 )

聽 聽 if MsgGet( "Entre titulo de una ventana abierta", "Titulo:", @cTitle ) .and. !empty( cTitle )

聽 聽 聽 聽 oWnd := TWCapture():New( AllTrim( cTitle ) )
聽 聽 聽 聽 Jugar( oWnd )

聽 聽 else

聽 聽 聽 聽 MsgAlert( "No ha elegido ningun titulo de ventana" + CRLF + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽"Ejecuto el WorPad y capturamos la ventana" )

聽 聽 聽 聽 WinExec( "NotePad.exe Demo01.prg" )

聽 聽 聽 聽 oWnd := TWCapture():New( "demo01 - bloc de notas" )
聽 聽 聽 聽 Jugar( oWnd )

聽 聽 endif

return nil

//----------------------------------------------------------------------------//

static function Jugar( oWnd )

聽 聽 聽 聽 local cTitle := oWnd:cTitle

聽 聽 聽 聽 if oWnd:lCaptured

聽 聽 聽 聽 聽 聽 MsgAlert( "Muy bien, ya lo tenemos" + CRLF + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "Hemos capturado la ventana con titulo: " + cTitle + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 CRLF + "Ahora vamos a jugar con ella" )

聽 聽 聽 聽 聽 聽 MsgInfo( "La centramos" )
聽 聽 聽 聽 聽 聽 oWnd:Center()

聽 聽 聽 聽 聽 聽 MsgInfo( "Pinto una linea" )
聽 聽 聽 聽 聽 聽 oWnd:Line( 0, 0, 500, 500 )

聽 聽 聽 聽 聽 聽 MsgInfo( "La desplazo a la izquierda" )
聽 聽 聽 聽 聽 聽 oWnd:Move( 0, 0 )

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora minimizo" )
聽 聽 聽 聽 聽 聽 oWnd:Minimize()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora maximizo" )
聽 聽 聽 聽 聽 聽 oWnd:Maximize()

聽 聽 聽 聽 聽 聽 MsgInfo( "La restauro" )
聽 聽 聽 聽 聽 聽 oWnd:Restore()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora cambio titulo" )
聽 聽 聽 聽 聽 聽 oWnd:SetText( "TWCapture captura ventanas - by Manu Exposito 2001" )

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora la oculto" )
聽 聽 聽 聽 聽 聽 oWnd:Hide()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora la muestro" )
聽 聽 聽 聽 聽 聽 oWnd:Show()

聽 聽 聽 聽 聽 聽 MsgInfo( "y ahora termino" )
聽 聽 聽 聽 聽 聽 oWnd:End()

聽 聽 聽 聽 else

聽 聽 聽 聽 聽 聽 MsgStop( "No se pudo capturar ninguna ventana" )
聽 聽 聽 聽 聽 聽 oWnd := nil

聽 聽 聽 聽 endif

return( nil )


Sample02
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
// TWCapture by Manu Exposito
// Demo02 de la clase TWCapture
//----------------------------------------------------------------------------//

#define CRLF chr( 13 ) + chr( 10 )

function Main()

聽 聽 local oWnd := TWCapture():New()
聽 聽 local cTitle := space( 40 )

聽 聽 oWnd:WCapture( "demo02 - bloc de notas" )

聽 聽 if !oWnd:lCaptured 聽 聽 聽// Si no esta la ventana la ejecutamos nosotros
聽 聽 聽 聽 WinExec( "NotePad.exe demo02.prg" )
聽 聽 聽 聽 oWnd:WCapture( "demo02 - bloc de notas" ) 聽// y la capturamos
聽 聽 endif

聽 聽 Jugar( oWnd )

return nil

//----------------------------------------------------------------------------//

static function Jugar( oWnd )

聽 聽 聽 聽 local cTitle := oWnd:cTitle

聽 聽 聽 聽 if oWnd:lCaptured

聽 聽 聽 聽 聽 聽 MsgAlert( "Muy bien, ya lo tenemos" + CRLF + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "Hemos capturado la ventana con titulo: " + cTitle + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 CRLF + "Ahora vamos a jugar con ella" )

聽 聽 聽 聽 聽 聽 MsgInfo( "La centramos" )
聽 聽 聽 聽 聽 聽 oWnd:Center()

聽 聽 聽 聽 聽 聽 MsgInfo( "Pinto una linea" )
聽 聽 聽 聽 聽 聽 oWnd:Line( 0, 0, 500, 500 )

聽 聽 聽 聽 聽 聽 MsgInfo( "La desplazo arriba a la izquierda" )
聽 聽 聽 聽 聽 聽 oWnd:Move( 0, 0 )

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora minimizo" )
聽 聽 聽 聽 聽 聽 oWnd:Minimize()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora maximizo" )
聽 聽 聽 聽 聽 聽 oWnd:Maximize()

聽 聽 聽 聽 聽 聽 MsgInfo( "La restauro" )
聽 聽 聽 聽 聽 聽 oWnd:Restore()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora cambio titulo" )
聽 聽 聽 聽 聽 聽 oWnd:SetText( "TWCapture captura ventanas - by Manu Exposito 2001" )

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora la oculto" )
聽 聽 聽 聽 聽 聽 oWnd:Hide()

聽 聽 聽 聽 聽 聽 MsgInfo( "Ahora la muestro" )
聽 聽 聽 聽 聽 聽 oWnd:Show()

聽 聽 聽 聽 聽 聽 MsgInfo( "y ahora termino" )
聽 聽 聽 聽 聽 聽 oWnd:End()

聽 聽 聽 聽 else

聽 聽 聽 聽 聽 聽 MsgStop( "No se pudo capturar ninguna ventana" )
聽 聽 聽 聽 聽 聽 oWnd := nil

聽 聽 聽 聽 endif

return( nil )

//----------------------------------------------------------------------------//


Saludos
Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 04:01 PM

Rodolfo,

Cuando una ventana recibe el foco, ejecuta su DATA bGotFocus que es un codeblock:

oWnd:bGotFocus = { || oWnd:SetText( "He recibido el foco" ) }

oWnd:bLostFocus = { || oWnd:SetText( "He perdido el foco" ) }

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 257
Joined: Tue May 16, 2006 04:46 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 04:48 PM

Gracias Don Antonio, es lo que buscaba.
Don Mario, gracias tambien a ti por tu interes.

RodolfoRBG
FWH 1307, xHarbour123 BCC582
rodolfoerbg@gmail.com
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Regres贸 el foco a esta ventana?
Posted: Fri Mar 02, 2012 07:52 PM
RodolfoRBG wrote:Gracias Jose Luis, pero donde lo pondria? en ON INIT? en VALID? o en que parte esta monitoreando cuando se pasa el foco a la ventana?



Primero defino la oWnd static, luego hago esto en mi prg

IF oWndInscri == NIL
....
...
...
ELSE
oWnd:Restore()
oWnd:SetFocus()

ENDIF

esto es idea inicial del colega Cruz Alfredo...
Dios no est谩 muerto...



Gracias a mi Dios ante todo!

Continue the discussion