Page 1 of 2

When one form could not be SetFocused

Posted: Thu May 15, 2014 3:10 pm
by Pablo César
I would like to tell you guys, my experience about SetFocus.

Better than words is preferable to show source codes in place of.

Code: Select all

#include <hmg.ch>

Function Main()
DEFINE WINDOW Form_1 AT 219 , 253 WIDTH 678 HEIGHT 426 ;
	TITLE "Main Form" MAIN ON INIT Second_Form()

END WINDOW
MAXIMIZE WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function Second_Form()
DEFINE WINDOW Form_2 AT 200 , 400 WIDTH 478 HEIGHT 426 ;
	TITLE "Second Form" CHILD ON INIT Third_Form()
	
    DEFINE BUTTON Button_1
	    ROW    50
	    COL    50
	    WIDTH  100
	    HEIGHT 28
	    ACTION (Return_Third(),SetProperty("Form_2","Label_1","VISIBLE",.F.))
	    CAPTION "Back to Third"
	    FONTNAME "Arial"
	    FONTSIZE 9
	    TOOLTIP ""
	END BUTTON
	
	DEFINE LABEL Label_1
	    ROW    200
	    COL    50
	    WIDTH  220
	    HEIGHT 48
	    VALUE "No focus on Third Form...  :("
	    FONTNAME "Arial"
	    FONTSIZE 9
		VISIBLE .F.
	    BACKCOLOR Nil
	    FONTCOLOR RED
	END LABEL

END WINDOW
ACTIVATE WINDOW Form_2
Return Nil

Function Third_Form()
DEFINE WINDOW Form_3 AT 50 , 100 WIDTH 200 HEIGHT 300 ;
	TITLE "Third Form" CHILD ON LOSTFOCUS Return_Third()
	
	DEFINE LABEL Label_1
	    ROW    50
	    COL    10
	    WIDTH  200
	    HEIGHT 48
	    VALUE "Click on Second Form to see if LOSTFOCUS works"
	    FONTNAME "Arial"
	    FONTSIZE 9
	END LABEL
		
END WINDOW
ACTIVATE WINDOW Form_3
Return Nil

Function Return_Third()
DoMethod("Form_3","SetFocus")
SetProperty("Form_2","Label_1","VISIBLE",.T.)
Return Nil
Why ON LOSTFOCUS is not possible to return to the Third Form ? Only if focused on another form not being Third form... :?

Is it normal this ? I do not understand... Is somebody understanding this ?

I guess something with post events... :?

Re: When one form could not be SetFocused

Posted: Thu May 15, 2014 4:43 pm
by Javier Tovar
Hola Pablo César,

A mi parecer lo que hace un poco difícil de entender el comportamiento es lo siguiente:

1.- En Form_3 llamas con LostFocus a Return_Third() la cual contiene lo siguiente:

Code: Select all

Function Return_Third()
	DoMethod("Form_3","SetFocus")
	SetProperty("Form_2","Label_1","VISIBLE",.T.)
Return Nil
La cual hace referencia a la misma Form_3. A lo mejor lo que aquí esperas es que se quede en la misma Form_3, lo cual no es posible ya que al hacer click en Form_2 no hay nada que impida entrar a Form_2.

BUENO YO SUGIERO LO SIGUIENTE:

Code: Select all

#include <hmg.ch>

Function Main()
DEFINE WINDOW Form_1 AT 219 , 253 WIDTH 678 HEIGHT 426 ;
   TITLE "Main Form" MAIN ON INIT Second_Form()

END WINDOW
MAXIMIZE WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function Second_Form()
DEFINE WINDOW Form_2 AT 200 , 400 WIDTH 478 HEIGHT 426 ;
   TITLE "Second Form" CHILD ON INIT Third_Form() 
   
    DEFINE BUTTON Button_1
       ROW    50
       COL    50
       WIDTH  100
       HEIGHT 28
       ACTION (Return_Form_3())  //////////////////////////////// Return_Form_3()
       CAPTION "Back to Third"
       FONTNAME "Arial"
       FONTSIZE 9
       TOOLTIP ""
   END BUTTON
   
   DEFINE LABEL Label_1
       ROW    200
       COL    50
       WIDTH  220
       HEIGHT 48
       VALUE "No focus on Third Form...  :("
       FONTNAME "Arial"
       FONTSIZE 9
      VISIBLE .F.
       BACKCOLOR Nil
       FONTCOLOR RED
   END LABEL

END WINDOW
ACTIVATE WINDOW Form_2
Return Nil

Function Third_Form()
DEFINE WINDOW Form_3 AT 50 , 100 WIDTH 200 HEIGHT 300 ;
   TITLE "Third Form" CHILD ON GOTFOCUS EntraForm3() ON LOSTFOCUS Return_Third()    ////////////////ON GOT FOCUS
   
   DEFINE LABEL Label_1
       ROW    50
       COL    10
       WIDTH  200
       HEIGHT 48
       VALUE "Click on Second Form to see if LOSTFOCUS works"
       FONTNAME "Arial"
       FONTSIZE 9
   END LABEL
      
END WINDOW
ACTIVATE WINDOW Form_3
Return Nil

Function Return_Third()
*	DoMethod("Form_3","SetFocus")   //////////////////////////////QUITAR ESTA LINEA
	SetProperty("Form_2","Label_1","VISIBLE",.T.)
Return Nil

Function EntraForm3()
	SetProperty("Form_2","Label_1","VISIBLE",.F.)
Return Nil

PROCEDURE Return_Form_3()
	DoMethod("Form_3","SetFocus")
RETURN NIL
Espero haber aclarado tu duda.

Saludos.

When one form could not be SetFocused

Posted: Thu May 15, 2014 5:15 pm
by Pablo César
Hola Javier, gracias por tu atencion.
Javier Tovar wrote:La cual hace referencia a la misma Form_3. A lo mejor lo que aquí esperas es que se quede en la misma Form_3
Si, es eso lo que quiero que ocurra. De una forma u otra.
Javier Tovar wrote:lo cual no es posible ya que al hacer click en Form_2 no hay nada que impida entrar a Form_2
Si, entiendo. Pero quiero que vuelva al Form_3.

Por ejemplo: si clicas en el form_1, quiero que vuelva al form_3 y si clicas en el form_2 quiero que vuelva al form_3 y si clicas fuera (en el desktop) tambien quiero que vuelva al form_3.

Javier, el ejemplo que sugieres, no estás tratando de retornar al form_3.

Yo creo que debe haber una forma de interrumpir el SetFocus al form_2, algo que se pueda implementar en el LostFocus del Form_3.

Image

Hi Javier, thanks for your kind of attention.

Yeah, that's what you want to happen. In one way or another. (To mkae focus on the same form).

Yes, I understand that there nothing which can except to make focus in form_2. But I want to return to Form_3.

For example: if you click on the Form_1, I want to return to form_3 and if you click on the form_2 form_3 want to return to and if you click out (on the desktop) I also want to return to form_3.

Javier, the example you suggest, you are not trying to return to form_3.

I think there must be a way to interrupt the SetFocus to form_2, which can be implemented in the function which act in LostFocus Form_3.

Re: When one form could not be SetFocused

Posted: Thu May 15, 2014 5:18 pm
by Javier Tovar
Hola Pablo César,
Pablo César wrote:Javier, el ejemplo que sugieres, no estás tratando de retornar al form_3.
Efectivamente no trato de retornar a Form_3. Ok vere que se puede hacer.

Saludos.

When one form could not be SetFocused

Posted: Thu May 15, 2014 5:24 pm
by Pablo César
Javier Tovar wrote:vere que se puede hacer
No te preocupes, Javier. Es algo dificil y quien sabe imposible. Pero yo consegui solo con forzar el retorno al form_3 desde el form_2 y tendré que hacerlo tambien desde el form_1. No es dramático, porque ya tengo algo. Simplesmente me gustaria saber si hay alguna forma que pueda interrumpir el próximo evento. Es decir, ejecute algo antes del evento LOST FOCUS y antes de ser ejecutado el p´roximo evento (el GOTFOCUS en Form_2) pueda ser abortado, dando lugar a que se quede en el form_3.

Image

Do not worry, Javier. It's difficult and who knows impossible. But I got only forcing the return to form_3 from the form_2 and have to do it the same to the Form_1. It is not dramatic, because I have something already. But it would be wonder to count with any way that would disrupt the upcoming event. I mean, run something before LOSTFOCUS event and before being executed the next event (GOTFOCUS in Form_2) can be aborted, causing the stay in the form_3.

Re: When one form could not be SetFocused

Posted: Thu May 15, 2014 5:27 pm
by Rathinagiri
Hi Pablo,

If you want to retain the focus in a particular window, why can't you define that window as modal?

When one form could not be SetFocused

Posted: Thu May 15, 2014 5:31 pm
by Pablo César
Rathinagiri wrote:If you want to retain the focus in a particular window, why can't you define that window as modal?
Yes, I tried that too. Good point of you Rathi, but I also need to get focus from form_2 (let say) or to collect mouse position at Form_2, for example.

When one form could not be SetFocused

Posted: Thu May 15, 2014 5:33 pm
by Pablo César
Because the goal is to know when mouse event clicked out from current form (let say form_3) and then execute something.

Re: When one form could not be SetFocused

Posted: Thu May 15, 2014 5:41 pm
by Javier Tovar
Hola Pablo César,

Pon en Form_1 y Form_2 "ON MOUSECLICK Return_Form_3()"

Saludos

Re: When one form could not be SetFocused

Posted: Thu May 15, 2014 6:05 pm
by Rathinagiri
Consider Windows Desktop as a window. All other windows are placed on this window as child windows.

Lostfocus of Form_3 need not be clicked to Form_2 but might be any other window on the desktop even the desktop itself.

So, if you want to send back the focus to Form_3, you can write this code in Form_2's on gotfocus.