_SetNextFocus()

Source code related resources

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

_SetNextFocus()

Post by Pablo César »

To our Development Team,

This _SetNextFocus() is usefull when we want to advance forward to the next item (like a TAB).

But I did not found any other function that could allow to advance backward to the previous item (like shift+tab).

I saw _SetNextFocus() uses the GetNextDlgTabItem C function.
Screen3.png
Screen3.png (12.03 KiB) Viewed 6107 times
Reading MSDN about it, says the 3rd parameter (logical type) is for next/back.

If you agree and believe would it be useful, we can use this same function:
Screen1.png
Screen1.png (25.91 KiB) Viewed 6107 times
Changing something like this one:

Code: Select all

*-----------------------------------------------------------------------------*
Procedure _SetNextFocus(lNext)
*-----------------------------------------------------------------------------*
Local i , NextControlHandle

DEFAULT lNext := .T.

NextControlHandle := GetNextDlgTabITem ( GetActiveWindow() , GetFocus() , lNext )

i := ascan ( _HMG_SYSDATA [3] , NextControlHandle )

If i > 0 
   If _HMG_SYSDATA [1] [i] == 'BUTTON'
      SetFocus( NextControlHandle )
      SendMessage ( NextControlHandle , BM_SETSTYLE , LOWORD ( BS_DEFPUSHBUTTON ) , 1 )
   Else
      If lNext
         InsertTab()
	  Else
	     InsertShiftTab()
	  Endif
   EndIf
Else
   If lNext
      InsertTab()
   Else
      InsertShiftTab()
   Endif
EndIf
Return
Then this function will have more one finality. Useful when we need to move Next/Back of controls by arrows keys, for example.

What do you think Claudio ? Is it posible ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

_SetNextFocus()

Post by Pablo César »

Hi Claudio,

It's me again...

Tried to use this at this case but it doesn't worked ! Always going to next button... :(

I've solved with just simple: InsertShiftTab() and InsertTab()
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: _SetNextFocus()

Post by BeGeS »

I return to this old topic because what I want to ask is related. Even perhaps solved elsewhere.

As always, my clients are accustomed to ENTER or DOWN ARROW to advance, and ESCAPE or UP ARROW to step back. If I now propose to use TAB and SHIFT-TAB, I'm thrown by a balcony. :?

So the first thing I did when I started with HMG is a function that avoids using the TAB key, allowing the user to move from the keyboard "as God commands". :mrgreen:

But I have a problem: if I open the same program three times and play with it on the screen, passing from one window to another, there comes a time when the function I mentioned is lost. But the most curious thing is that I follow and recover it after x? movements. I have not found a logic to that disconnect-connection.

The question would be: when or how does a key lose its assigned function?

Here is the function:

Code: Select all

#include "HMG.ch"

FUNCTION INICIO()
PUBLIC TSALIR:=0

  SET NAVIGATION EXTENDED

  DEFINE WINDOW WIN01 AT 0,0 ...etc

    DEFINE FRAME ...
    END FRAME

    @ 062,040 LABEL TXL1 ...
    @ 092,040 LABEL TXL2 ...
    @ 122,040 LABEL TXL3 ...
    @ 152,040 LABEL TXL4 ... etc

    KEYSALIR()     <====|
 
    @ 062,200 TEXTBOX CODI ...
    @ 092,200 TEXTBOX NOMB ...
    @ 122,200 TEXTBOX DIRE ...
    @ 152,200 TEXTBOX POBL ... etc

    @ 313,665 BUTTON BOT01 ...
    @ 353,665 BUTTON BOT02 ...
    @ 393,665 BUTTON BOT03 ... etc

  END WINDOW

  CENTER WINDOW WIN01
  ACTIVATE WINDOW WIN01

RETURN

// --- PREPARA TECLAS DE SALIDA DE TEXBOX / BUTTON ---
FUNCTION KEYSALIR()
  ON KEY ESCAPE ACTION IMITAKEY()
  ON KEY UP     ACTION IMITAKEY()
  ON KEY DOWN   ACTION IMITAKEY()
RETURN

// --- SALIR DE TEXBOX CON ESCAPE O FLECHAS IMITANDO A SHIFT+TAB O TAB ---
FUNCTION IMITAKEY()
LOCAL VKPULSA:=HMG_GETLASTVIRTUALKEYDOWN()

  TSALIR:=0

  IF VKPULSA==VK_ESCAPE
    HMG_CLEANLASTVIRTUALKEYDOWN() ; HMG_PRESSKEY(VK_SHIFT,VK_TAB)
    TSALIR:=1
  ENDIF

  IF VKPULSA==VK_UP
    HMG_CLEANLASTVIRTUALKEYDOWN() ; HMG_PRESSKEY(VK_SHIFT,VK_TAB)
    TSALIR:=2
  ENDIF

  IF VKPULSA==VK_DOWN
    HMG_CLEANLASTVIRTUALKEYDOWN() ; HMG_PRESSKEY(VK_TAB)
    TSALIR:=3
  ENDIF

RETURN
I get by with a little help from my friends
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: _SetNextFocus()

Post by BeGeS »

Translate to español (¡uf!)

Retomo este antiguo tema porque lo que quiero preguntar está relacionado. Incluso quizá resuelto en otra parte.

De siempre, mis clientes están acostumbrados a ENTER o FLECHA ABAJO para avanzar, y ESCAPE o FLECHA ARRIBA para retroceder. Si ahora planteo utilizar TAB y SHIFT-TAB, me arrojan por un balcón.

Por eso, lo primero que he hecho al comenzar con HMG es una función que evita utilizar la tecla TAB, permitiendo que el usuario se mueva desde el teclado “como Dios manda”.

Pero tengo un problema: si abro el mismo programa tres veces y juego con él en la pantalla, pasando de una ventana a otra, llega un momento en el que se pierde la función que he mencionado. Pero lo más curioso es que sigo y la recupera al cabo de x? movimientos. No he encontrado una lógica a esa desconexión-conexión.

La pregunta sería: ¿cuándo o cómo una tecla pierde la función asignada?
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: _SetNextFocus()

Post by serge_girard »

Bernardo,

If I understood well you are trying to imitate old DOS behaviour? (In order NOT to get thrown from a balcony... or worse).
I once also had to convert an old Clipper app with keeping the same screen behaviour: this do-able but not desirable. You will have to use a lot of coding (which has nothing to do with the original functionality of your app) which makes it all hard to maintain and debug.

When users are common to old app's they don't really want to change their habits. Example: they know all kinds of input-codes by heart and don't want to use listboxes or comboxes (which are pre-filled with the possible options).

Maybe you can convince them to try and let them discover the new possibilities.

I will take a look at your sample anyway.

Serge
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: _SetNextFocus()

Post by serge_girard »

Bernardo,

I tried your sample in W7 and this works fine:

Code: Select all

#include "HMG.ch"

FUNCTION MAIN()
PUBLIC TSALIR:=0

  SET NAVIGATION EXTENDED

   DEFINE WINDOW WIN01   ;
      AT 0,0	              ;
      HEIGHT 600	;  
      WIDTH  600	;
      TITLE "Bernardo";	
      MAIN;
      BACKCOLOR SILVER 

 

   @ 10,10 LABEL Label_1;
      VALUE "CODI" ;
      WIDTH  150 ;
      HEIGHT 30 ;
      FONT 'Arial' SIZE 12  ;
      BACKCOLOR BLUE	;
      FONTCOLOR ORANGE BOLD

   @ 50,10 LABEL Label_2;
      VALUE "NOMB" ;
      WIDTH  150 ;
      HEIGHT 30 ;
      FONT 'Arial' SIZE 12  ;
      BACKCOLOR BLUE	;
      FONTCOLOR ORANGE BOLD

   @ 90,10 LABEL Label_3;
      VALUE "DIRE" ;
      WIDTH  150 ;
      HEIGHT 30 ;
      FONT 'Arial' SIZE 12  ;
      BACKCOLOR BLUE	;
      FONTCOLOR ORANGE BOLD

   @ 130,10 LABEL Label_4;
      VALUE "POBL" ;
      WIDTH  150 ;
      HEIGHT 30 ;
      FONT 'Arial' SIZE 12  ;
      BACKCOLOR BLUE	;
      FONTCOLOR ORANGE BOLD


    KEYSALIR()      
 

   @ 10,200 TEXTBOX CODI ;
      TOOLTIP 'CODI'	;
      WIDTH 120 ;
      MAXLENGTH 30	;
      VALUE 'CODI'    ;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('WIN01','CODI','BackColor', WHITE );
      ON LOSTFOCUS SetProperty('WIN01','CODI','BackColor', SILVER)

   @ 50,200 TEXTBOX NOMB ;
      TOOLTIP 'NOMB'	;
      WIDTH 120 ;
      MAXLENGTH 30	;
      VALUE 'NOMB'    ;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('WIN01','NOMB','BackColor', WHITE );
      ON LOSTFOCUS SetProperty('WIN01','NOMB','BackColor', SILVER)

   @ 90,200 TEXTBOX DIRE ;
      TOOLTIP 'DIRE'	;
      WIDTH 120 ;
      MAXLENGTH 30	;
      VALUE 'DIRE'    ;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('WIN01','DIRE','BackColor', WHITE );
      ON LOSTFOCUS SetProperty('WIN01','DIRE','BackColor', SILVER)

   @ 130,200 TEXTBOX POBL ;
      TOOLTIP 'POBL'	;
      WIDTH 120 ;
      VALUE 'DIRE'    ;
      BACKCOLOR SILVER	;
      FONTCOLOR BLUE BOLD ;
      ON GOTFOCUS  SetProperty('WIN01','POBL','BackColor', WHITE );
      ON LOSTFOCUS SetProperty('WIN01','POBL','BackColor', SILVER)

/*
    @ 313,665 BUTTON BOT01 ...
    @ 353,665 BUTTON BOT02 ...
    @ 393,665 BUTTON BOT03 ... etc */

  END WINDOW

  CENTER WINDOW WIN01
  ACTIVATE WINDOW WIN01

RETURN




// --- PREPARA TECLAS DE SALIDA DE TEXBOX / BUTTON ---
FUNCTION KEYSALIR()
  ON KEY ESCAPE ACTION IMITAKEY()
  ON KEY UP     ACTION IMITAKEY()
  ON KEY DOWN   ACTION IMITAKEY()
RETURN




// --- SALIR DE TEXBOX CON ESCAPE O FLECHAS IMITANDO A SHIFT+TAB O TAB ---
FUNCTION IMITAKEY()
LOCAL VKPULSA:=HMG_GETLASTVIRTUALKEYDOWN()

  TSALIR:=0

  IF VKPULSA==VK_ESCAPE
     HMG_CLEANLASTVIRTUALKEYDOWN() 
     HMG_PRESSKEY(VK_SHIFT,VK_TAB)
     TSALIR:=1
  ENDIF

  IF VKPULSA==VK_UP
    HMG_CLEANLASTVIRTUALKEYDOWN()   
    HMG_PRESSKEY(VK_SHIFT,VK_TAB)
    TSALIR:=2
  ENDIF

  IF VKPULSA==VK_DOWN
    HMG_CLEANLASTVIRTUALKEYDOWN()   
    HMG_PRESSKEY(VK_TAB)
    TSALIR:=3
  ENDIF

RETURN
Try it yourself!

Serge
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: _SetNextFocus()

Post by Rathinagiri »

Initially I was also thinking of providing the same screen effect from the good old DoS screen.

However later I had realized that GUI users don't care about the old screens. They will change to the new screen without any problem.

On the other hand, I also welcome if it is possible to maintain the old screen layout and functionalities it is an added advantage.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: _SetNextFocus()

Post by BeGeS »

Thank you, Serge, for your time.

Your help has been very useful because it has allowed me to know where is not problem. This function KEYSALIR() works well within a group of textbox, as we have both been able to verify, and in both W7 and W10 ... provided there are no other things in between.

I think I have located where the mismatch occurs: it is a textbox that asks the NIF (tax identification number in Spain) and calculates the control letter that completes the data. I have not had time to do tests yet, but it should be there. The strange thing is that it does not affect the window where it is working, but to others that are open, even if it is Notepad++, where also the arrow keys become silly.

As for changing the action of certain keys would occupy many lines of code, I do not agree. I use a general .PRG (as a .CH file) for all applications, where I include this kind of thing. You see: shorter KEYSALIR() than SET NAVIGATION EXTENDED. :lol:

Again thanks. ;)
I get by with a little help from my friends
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: _SetNextFocus()

Post by BeGeS »

Rathinagiri wrote: Tue Jul 18, 2017 12:23 pm Initially I was also thinking of providing the same screen effect from the good old DoS screen.
However later I had realized that GUI users don't care about the old screens. They will change to the new screen without any problem.
On the other hand, I also welcome if it is possible to maintain the old screen layout and functionalities it is an added advantage.
I agree with this last one that you say, as long as there is no conflict, that each one use the key that prefers to advance or back.

But I do not agree with what you say before, my admired Rathinagiri.

For me there are no GUI users and console users. There are jobs and jobs. And each type of work requires a suitable tool. The user must judge, never a developer locked in his study, because what is theoretically good, in practice may be useless.

A real example: an administrative who every afternoon devotes an hour to making invoices, and in that time he makes about fifty. The references are not many (it's a cheese factory) and are well coded, so that it practically works with one hand, the right, "spilled" on the numeric block, INTRO and arrows. It does so at a dizzying speed. If to move between the different fields had to use TAB and SHIFT-TAB, it would lose much operability.

-----------------------------------------------------------------------------------------------------------------------------------
(Para los miembros hispanohablantes)

Estoy de acuerdo con esto último que dices, pues mientras no exista conflicto, que cada cual utilice la tecla que prefiera para avanzar o retroceder.

Pero no estoy de acuerdo con lo dices antes, mi admirado Rathinagiri.

Para mí no existen usuarios GUI y usuarios consola. Lo que hay son trabajos y trabajos. Y cada tipo de trabajo requiere una herramienta adecuada, siendo el usuario el que debe juzgar, nunca un desarrollador encerrado en su estudio, pues lo que teóricamente es bueno, en la práctica puede ser poco útil.

Un ejemplo real: un administrativo que todas las tardes dedica una hora a confeccionar facturas, y en ese tiempo elabora unas cincuenta. Las referencias no son muchas (es una fábrica de quesos) y están bien codificadas, de forma que prácticamente trabaja con una sola mano, la derecha, “derramada” sobre el bloque numérico, INTRO y flechas. Lo hace a velocidad de vértigo. Si para moverse entre los distintos campos tuviera que usar TAB y SHIFT-TAB, perdería mucha operatividad.
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: _SetNextFocus()

Post by serge_girard »

Bernardo,

You're right when it comes to pure data-entry DOS-like is the best: no mouse-interactions (or very few) , just a few NUM-pad keys will solve all.

Serge
There's nothing you can do that can't be done...
Post Reply