FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour ButtonBmp + Escape
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
ButtonBmp + Escape
Posted: Thu Dec 20, 2012 04:40 PM

Amigos todos,
Tengo un pequeño inconveniente con los botones BUTTONBMP y la tecla ESCAPE, en ambiente MDI utilizando dialogs NOWAIT incrustados en MdiChilds.
He condicionado la salida (odlg y Child) mediante GetKeyState(VK_ESCAPE) y me funciona correctamente.
Ahora bien, si el focus lo tiene cualquier objeto que no sea ButtonBmp, la condición trabaja bien. Pero si el usuario hace click sobre cualquier ButtonBmp y i suelta la tecla del ratón fuera del botón, quedando el foco en este, y luego presiona escape, se dispara la acción de la tecla escape y solo cierra el dialog, quedando activa la child. Es decir, si cualquier BUTTONBMP tiene el foco y se oprime la tecla escape, la condición dada con GetKeyState(VK_ESCAPE) se irrespeta, y únicamente cierra el dialog.

¿Alguno de ustedes experimentado este problema? ¿Tiene la solución?
Agradezco de antemano cualquier comentario al respecto. Utilizo Fwh1204-xHarbour-PellesC

Saludos.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 845
Joined: Sun Oct 09, 2005 05:36 PM
Re: ButtonBmp + Escape
Posted: Thu Dec 20, 2012 08:37 PM

Francisco,
Establece que cuando se cierre el dialogo, cierra la window
saludos
paco

____________________

Paco
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: ButtonBmp + Escape
Posted: Thu Dec 20, 2012 11:19 PM

Francisco, gracias, asi lo hago.
Mira aqui: viewtopic.php?f=3&t=25387#p138243
Saludos.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 694
Joined: Fri Oct 07, 2005 06:58 AM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 10:23 AM
A mi me pasaba a menudo.
Da igual los controles que pusiera, se seguía cerrando el cuadro de dialog sin cerrar el mdi.
Además no podía reproducirlo. Pasaba a veces.

Hasta que que lo he conseguido anulando las llamadas en KeyChar que cierran la ventana

Code (fw): Select all Collapse
METHOD KeyChar( nKey, nFlags ) CLASS TMdiChild

   if ::bKeyChar != nil  //fgondi
      return Eval( ::bKeyChar, nKey, nFlags )
   endif
/*
   if nKey == VK_ESCAPE
      ::End()
      return 0
   endif
*/
return Super:KeyChar( nKey, nFlags )


Code (fw): Select all Collapse
METHOD KeyChar( nKey, nFlags ) CLASS TDialog

   if nKey == VK_ESCAPE
      if ::oWnd = nil .or. ::oWnd:IsKindOf( "TDIALOG" ) .or. ::oWnd:IsKindOf( "TMDIFRAME" )
         if SetDialogEsc()
            ::End()
         endif
      endif
   /* fgondi
      if ::oWnd != nil .and. ( ::IsKindOf( "TMDICHILD" ) .or. ;
         ::IsKindOf( "TDIALOG" ) .or. ::IsKindOf( "TMDIFRAME" ) )
         if SetDialogEsc()
            //::End() //fgondi
         endif
      endif
   */      
      return nil     
   endif

return Super:KeyChar( nKey, nFlags )
Un saludo

Fernando González Diez

ALSIS Sistemas Informáticos
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 01:53 PM
Fernando,
Gracias por contestar.
Hice las modificaciones indicadas en copias de las classes TMDICHILD y TDIALOG, y el comportamiento es el mismo.
Como explicaba antes, solamente sucede si el focus lo tiene cualquier TBUTTONBMP al momento de oprimir la tecla ESCAPE.

Lo que pretendo es que el usuario no pueda salir del DIALOG NOWAIT incrustado en MDICHILD, si oprime ESCAPE. Vale decir que este comportamiento solo es requerido en ciertos dialogs, por lo tanto, el objetivo no es deshabilitar ESCAPE en todo el programa.

Prueba el siguiente código y lo comprobarás. En este comparo las classes TBUTTONBMP vs TBTNBMP . Con la segunda funciona todo bien, pero con la otra no.
Continúo pensando que el problema está en la Class TBUTTON (Button.prg), y me estoy concentrando en eso, ya que he intentado de todo lo que he encontrado aquí en el foro, sin resultados.

Code (fw): Select all Collapse
//------------------------------------------------
//PRUEBA 4 MDI + MDICHILD + DIALOG NOWAIT INCRUSTADO + ESCAPE
//-------------------------------------------------

#include "FiveWin.ch"

#define COLOR_BTNFACE   15

//-------------------------------------
function Main()
local oWnd, oBar

DEFINE WINDOW oWnd TITLE "MDIChilds" MDI

DEFINE BUTTONBAR oBar _3D OF oWnd

DEFINE BUTTON OF oBar ACTION child(oWnd)

ACTIVATE WINDOW oWnd maximized

return nil

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

function Child(oWnd)
local oWndChild, oDlg, oBtn1, oBtn2, oBtn3, oBtn4
   
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5,5 TO 6,6;
COLOR "N/W" ;
BORDER NONE  NOMAXIMIZE NOMINIMIZE // prevent resizing

oWndChild:bGotFocus  = { || oDlg:SetFocus() }

DEFINE DIALOG oDlg FROM 150, 150 TO 400, 600 STYLE WS_CHILD ;
OF oWndChild TITLE "Dialog from Child- Window" PIXEL  TRANSPARENT 


@ 36, 10 SAY "CLASS TBUTTONBMP" OF oDlg PIXEL

@ 50, 10 BUTTONBMP oBtn1 OF oDlg ACTION MsgInfo( "Prueba de Focus" ) ;
         PROMPT "&Test" TEXTRIGHT SIZE 80, 20 PIXEL

@ 80, 10 BUTTONBMP oBtn2 OF oDlg ACTION oDlg:End() ;
         PROMPT "&Exit" TEXTRIGHT SIZE 80, 20 PIXEL



@ 36, 150 SAY "CLASS TBTNBMP" OF oDlg PIXEL

@ 50, 150 BTNBMP oBtn3 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Focus-test" ;
ACTION MsgAlert( "Focus-test", "Attention" )  
oBtn3:lTransparent = .t.                      

@ 80, 150 BTNBMP oBtn4 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Exit" ;
ACTION oDlg:End()
oBtn4:lTransparent = .t.    

ACTIVATE DIALOG oDlg NOWAIT ;
    VALID if(!GetKeyState(VK_ESCAPE), ( oWndChild:End(), .t. ), .F.) ;
    ON INIT oDlg:Move(0,0) 

ACTIVATE WINDOW oWndChild ;
    ON INIT oWndChild:SetSize(oDlg:nWidth,oDlg:nHeight)

return nil

Nuevamente, muchas gracias por tu amabilidad.
Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 03:52 PM
por favor intenta agregar esto:
solo funciona con xharbour, si usas harbour debes incluir la lib xhb y el archivo hbcompat.ch

salu2
carlos vargas

Code (fw): Select all Collapse
....
   OVERRIDE METHOD GetDlgCode IN CLASS TButton  WITH KGetDlgCode
....


/*-------------------------------------------------------------------------------------------------*/

FUNCTION KGetDlgCode( nLastKey )
   LOCAL Self := HB_QSelf()

   ::oWnd:nLastKey := nLastKey

   DO CASE
   CASE ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TFOLDER"   ) .or. ::oWnd:oWnd:IsKindOf( "TFOLDEREX" )      )
      RETURN DLGC_WANTALLKEYS
   CASE nLastKey == VK_ESCAPE .and. ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TWINDOW" ) .and. ::oWnd:IsKindOf( "TDIALOG" ) )
      RETURN DLGC_WANTALLKEYS
   ENDCASE

RETURN NIL


si no funciona intenta agregar otro case
Code (fw): Select all Collapse
   ...
   CASE nLastKey == VK_ESCAPE .and. ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TMDICHILD"   ) .and. ::oWnd:IsKindOf( "TDIALOG" ) )
      RETURN DLGC_WANTALLKEYS
   ENDCASE

y aun no
Code (fw): Select all Collapse
IF nLastkey == VK_ESCAPE
    ? ::oWnd:Classname()
    IF ::oWnd:oWnd != NIL
         ?::oWnd:oWnd:Classname()
    ENDIF
ENDIF

muestra el resultado, please
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 04:14 PM
Carlos,
Muchisimas gracias. Precisamente hace unos instantes acabo de postear para Uwe, la posible solución que encontré y es esta.
Voy a probar tu código.
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

METHOD GetDlgCode( nLastKey ) CLASS TButton

   ::oWnd:nLastKey := nLastKey

/*
   if ::oWnd != nil .and. ( ::IsKindOf( "TFOLDER" ) .or. ;   //Original
                                 ::IsKindOf( "TFOLDEREX" ) )
       return DLGC_WANTALLKEYS
   endif
*/

  //FranciscoA 21/12/2012
  if ::oWnd:oWnd != nil 
      if ::oWnd:oWnd:IsKindOf( "TFOLDER" ) .or. ::oWnd:oWnd:IsKindOf( "TFOLDEREX" ) 
         return DLGC_WANTALLKEYS
      endif

      if nLastKey == VK_ESCAPE    
         if ::oWnd:IsKindOf( "TDIALOG" ) 
            return DLGC_WANTALLKEYS
         endif
      endif
  endif

return nil

Code (fw): Select all Collapse
//------------------------------------------------
//PRUEBA 4 MDI + MDICHILD + DIALOG NOWAIT INCRUSTADO + ESCAPE
//-------------------------------------------------

#include "FiveWin.ch"

#define COLOR_BTNFACE   15

//-------------------------------------
function Main()
local oWnd, oBar

DEFINE WINDOW oWnd TITLE "MDIChilds" MDI

DEFINE BUTTONBAR oBar _3D OF oWnd

DEFINE BUTTON OF oBar ACTION child(oWnd)

ACTIVATE WINDOW oWnd maximized

return nil

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

function Child(oWnd)
local oWndChild, oDlg, oBtn1, oBtn2, oBtn3, oBtn4
local bExit

  
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5,5 TO 6,6;
COLOR "N/W" ;
BORDER NONE  NOMAXIMIZE NOMINIMIZE // prevent resizing

oWndChild:bGotFocus  = { || oDlg:SetFocus() }

DEFINE DIALOG oDlg FROM 150, 150 TO 400, 600 STYLE WS_CHILD ;
OF oWndChild TITLE "Dialog from Child- Window" PIXEL  TRANSPARENT 


@ 36, 10 SAY "CLASS TBUTTONBMP" OF oDlg PIXEL

@ 50, 10 BUTTONBMP oBtn1 OF oDlg ACTION MsgInfo( "Prueba de Focus" ) ;
         PROMPT "&Test" TEXTRIGHT SIZE 80, 20 PIXEL

@ 80, 10 BUTTONBMP oBtn2 OF oDlg ACTION ( oWndChild:End() );
         PROMPT "&Exit" TEXTRIGHT SIZE 80, 20 PIXEL



@ 36, 150 SAY "CLASS TBTNBMP" OF oDlg PIXEL

@ 50, 150 BTNBMP oBtn3 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Focus-test" ;
ACTION MsgAlert( "Focus-test", "Attention" )  
oBtn3:lTransparent = .t.                      

@ 80, 150 BTNBMP oBtn4 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Exit" ;
ACTION oDlg:End()
oBtn4:lTransparent = .t.    

bExit := {|| MsgInfo("Hello...!!! Do you like music?"+CRLF+;
             "Voyage at the bottom of the bath (The Shadows)") }

ACTIVATE DIALOG oDlg NOWAIT ;
    VALID if(!GetKeyState(VK_ESCAPE), ( oWndChild:End(), .t. ), .F.) ;     //with the tbutton changes, if you not use getkeystate(), valid clause works as normal escape.
    ON INIT oDlg:Move(0,0) 

oWndChild:bPostEnd := {|| Eval(bExit) }

ACTIVATE WINDOW oWndChild ; 
    VALID .T. ;       //if(!GetKeyState(VK_ESCAPE),(MsgInfo("I go home."), .t.), .F.) ;
    ON INIT oWndChild:SetSize(oDlg:nWidth,oDlg:nHeight)

return nil

Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 04:29 PM
Hola Carlos,
He probado tu solución y funciona!!!.
Voy a mantener las dos opciones, por si acaso una de ellas me falla.
Code (fw): Select all Collapse
//------------------------------------------------
//PRUEBA 4 MDI + MDICHILD + DIALOG NOWAIT INCRUSTADO + ESCAPE
//-------------------------------------------------

#include "FiveWin.ch"

#define COLOR_BTNFACE   15


//-------------------------------------
function Main()
local oWnd, oBar

DEFINE WINDOW oWnd TITLE "MDIChilds" MDI

DEFINE BUTTONBAR oBar _3D OF oWnd

DEFINE BUTTON OF oBar ACTION child(oWnd)

ACTIVATE WINDOW oWnd maximized

return nil

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

function Child(oWnd)
local oWndChild, oDlg, oBtn1, oBtn2, oBtn3, oBtn4
local bExit

OVERRIDE METHOD GetDlgCode IN CLASS TButton  WITH KGetDlgCode
  
DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
FROM 5,5 TO 6,6;
COLOR "N/W" ;
BORDER NONE  NOMAXIMIZE NOMINIMIZE // prevent resizing

oWndChild:bGotFocus  = { || oDlg:SetFocus() }

DEFINE DIALOG oDlg FROM 150, 150 TO 400, 600 STYLE WS_CHILD ;
OF oWndChild TITLE "Dialog from Child- Window" PIXEL  TRANSPARENT 


@ 36, 10 SAY "CLASS TBUTTONBMP" OF oDlg PIXEL

@ 50, 10 BUTTONBMP oBtn1 OF oDlg ACTION MsgInfo( "Prueba de Focus" ) ;
         PROMPT "&Test" TEXTRIGHT SIZE 80, 20 PIXEL

@ 80, 10 BUTTONBMP oBtn2 OF oDlg ACTION ( oWndChild:End() );
         PROMPT "&Exit" TEXTRIGHT SIZE 80, 20 PIXEL



@ 36, 150 SAY "CLASS TBTNBMP" OF oDlg PIXEL

@ 50, 150 BTNBMP oBtn3 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Focus-test" ;
ACTION MsgAlert( "Focus-test", "Attention" )  
oBtn3:lTransparent = .t.                      

@ 80, 150 BTNBMP oBtn4 SIZE 50, 20 OF oDlg  2007 ;
CENTER ;
PROMPT "  &Exit" ;
ACTION oDlg:End()
oBtn4:lTransparent = .t.    

bExit := {|| MsgInfo("Hello...!!! Do you like music?"+CRLF+;
             "Voyage at the bottom of the bath (The Shadows)") }

ACTIVATE DIALOG oDlg NOWAIT ;
    VALID if(!GetKeyState(VK_ESCAPE), ( oWndChild:End(), .t. ), .F.) ;
    ON INIT oDlg:Move(0,0) 

oWndChild:bPostEnd := {|| Eval(bExit) }

ACTIVATE WINDOW oWndChild ; 
    VALID .T. ;    //if(!GetKeyState(VK_ESCAPE),(MsgInfo("I go home."), .t.), .F.) ;
    ON INIT oWndChild:SetSize(oDlg:nWidth,oDlg:nHeight)

return nil

/*-------------------------------------------------------------------------------------------------*/

FUNCTION KGetDlgCode( nLastKey )
   LOCAL Self := HB_QSelf()

   ::oWnd:nLastKey := nLastKey

   DO CASE
   CASE ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TFOLDER"   ) .or. ::oWnd:oWnd:IsKindOf( "TFOLDEREX" )      )
      RETURN DLGC_WANTALLKEYS
   CASE nLastKey == VK_ESCAPE .and. ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TWINDOW" ) .and. ::oWnd:IsKindOf( "TDIALOG" ) )
      RETURN DLGC_WANTALLKEYS
   ENDCASE

RETURN NIL

Muchisimas gracias. Estamos a la orden.
Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 08:03 PM

Francisco, gracias por el arreglo

lo otro, si utilizas la clase TSBROWSE, y te posisionas en cualquier columna y presionas la tecla ESC este se sale del dialogo dejando todo abierto

Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: ButtonBmp + Escape
Posted: Fri Dec 21, 2012 09:38 PM

Hola Patricio.
No he usado la TSBROWSE. Sin embargo, si me envías un ejemplo autocontenido, y todos los componentes de la classe, podría intentarlo.
Saludos.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql

Continue the discussion