which control is in focus?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

which control is in focus?

Post by dragancesu »

The form has two grid controls, one is active - in focus
I have a button that needs to call the function for active grid
How to find out which grid is active? or some other control?
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: which control is in focus?

Post by gfilatov »

dragancesu wrote: Wed Apr 10, 2019 9:07 pm The form has two grid controls, one is active - in focus
I have a button that needs to call the function for active grid
How to find out which grid is active? or some other control?
Hi Dragan,

Please take a look for the following discussion at

http://hmgforum.com/viewtopic.php?f=24&t=2807&p=25205
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: which control is in focus?

Post by bpd2000 »

It may help you

Code: Select all

#include "minigui.ch"

Function Main

DEFINE WINDOW Win_0 ;
ROW 0 ;
COL 0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE 'Panel Window Demo' ;
WINDOWTYPE MAIN 

DEFINE BUTTON BUTTON_1
ROW	 160
COL	 90
WIDTH	 200
CAPTION	 'Click Me!'
ACTION	 Test()
DEFAULT	 .T.
END BUTTON

END WINDOW

Center Window Win_0

Activate Window Win_0

Return Nil

Procedure Test

DEFINE WINDOW Win_1 ;
ROW 0 ;
COL 0 ;
WIDTH 500 ;
HEIGHT 300 ;
TITLE 'Panel in Modal Window' ;
WINDOWTYPE MODAL

DEFINE LABEL LABEL_0
ROW	 10
COL	 50
VALUE	 'Press F2 and F3 key ...'
WIDTH	 300
END LABEL

ON KEY ESCAPE ACTION ThisWindow.Release

DEFINE WINDOW Win_2 ;
ROW 30 ;
COL 30 ;
WIDTH 300 ;
HEIGHT 200 ;
VIRTUAL WIDTH 400 ;
VIRTUAL HEIGHT 400 ;
WINDOWTYPE PANEL

DEFINE LABEL LABEL_1
ROW	 10
COL	 10
VALUE	 'Panel window...'
WIDTH	 300
END LABEL

DEFINE BUTTON BUTTON_1
ROW	 40
COL	 10
CAPTION	 'Click Me!'
ACTION	 MsgInfo('Clicked!')
DEFAULT	 .T.
END BUTTON

DEFINE LABEL LABEL_2
ROW	 90
COL	 10
VALUE	 "Can do this!"
WIDTH	 300
END LABEL

DEFINE TEXTBOX TEXT_1
ROW	 120
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_2
ROW	 150
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_3
ROW	 180
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_4
ROW	 210
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_5
ROW	 240
COL	 10
VALUE	 'Test'
END TEXTBOX

END WINDOW

DEFINE TEXTBOX TEXT_1
ROW	 300
COL	 10
VALUE	 'Test'
END TEXTBOX

ON KEY F2 ACTION MsgInfo ( Win_2.FocusedControl, GetControlType(( Win_2.FocusedControl ), 'Win_2') )
ON KEY F3 ACTION Test2('Win_2')

END WINDOW

Center Window Win_1

// Panel windows are automatically activated through its parent
// so, only Win_1 must be activated.

Activate Window Win_1

Return


PROCEDURE Test2(cForm)
LOCAL cFoco, cTipo
cFoco := GetProperty(cForm,'FOCUSEDCONTROL')
cTipo := GETCONTROLTYPE( cFoco, cForm)
MSGINFO( cForm +CRLF+ cFoco +CRLF+ cTipo)
RETURN NIL

Code: Select all

#include "minigui.ch"

Function Main

Local aRows [20] [3]

	DEFINE WINDOW Win_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Press F2 and F3 key to Know Focused Control' ;
    MAIN

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		@ 10,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
	                JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 250,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
                	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER } 



ON KEY F2 ACTION MsgInfo ( Win_1.FocusedControl, GetControlType(( Win_1.FocusedControl ), 'Win_1') )
ON KEY F3 ACTION Test2('Win_1')

END WINDOW

Center Window Win_1

// Panel windows are automatically activated through its parent
// so, only Win_1 must be activated.

Activate Window Win_1

Return


PROCEDURE Test2(cForm)
LOCAL cFoco, cTipo
cFoco := GetProperty(cForm,'FOCUSEDCONTROL')
cTipo := GETCONTROLTYPE( cFoco, cForm)
MSGINFO( cForm +CRLF+ cFoco +CRLF+ cTipo)
RETURN NIL
BPD
Convert Dream into Reality through HMG
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: which control is in focus?

Post by mustafa »

Hi bpd2000
The first solution is giving Error with HMG
the sample corrected

Code: Select all

#include "minigui.ch"

Function Main

DEFINE WINDOW Win_0 ;
ROW 0 ;
COL 0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE 'Panel Window Demo' ;
WINDOWTYPE MAIN NOSIZE NOMAXIMIZE

DEFINE BUTTON BUTTON_1
ROW	 160
COL	 90
WIDTH	 200
CAPTION	 'Click Me!'
ACTION	 Test()
END BUTTON

END WINDOW

Center Window Win_0

Activate Window Win_0

Return Nil

Procedure Test

DEFINE WINDOW Win_1 ;
ROW 0 ;
COL 0 ;
WIDTH 500 ;
HEIGHT 300 ;
TITLE 'Panel in Modal Window' ;
WINDOWTYPE MODAL

DEFINE LABEL LABEL_0
ROW	 10
COL	 50
VALUE	 'Press F2 and F3 key ...'
WIDTH	 300
END LABEL

ON KEY ESCAPE ACTION ThisWindow.Release

DEFINE WINDOW Win_2 ;
ROW 30 ;
COL 30 ;
WIDTH 300 ;
HEIGHT 200 ;
VIRTUAL WIDTH 400 ;
PANEL

DEFINE LABEL LABEL_1
ROW	 10
COL	 10
VALUE	 'Panel window...'
WIDTH	 300
END LABEL

DEFINE BUTTON BUTTON_1
ROW	 40
COL	 10
CAPTION	 'Click Me!'
ACTION	 MsgInfo('Clicked!')
END BUTTON

DEFINE LABEL LABEL_2
ROW	 90
COL	 10
VALUE	 "Can do this!"
WIDTH	 300
END LABEL

DEFINE TEXTBOX TEXT_1
ROW	 120
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_2
ROW	 150
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_3
ROW	 180
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_4
ROW	 210
COL	 10
VALUE	 'Test'
END TEXTBOX

DEFINE TEXTBOX TEXT_5
ROW	 240
COL	 10
VALUE	 'Test'
END TEXTBOX

END WINDOW

DEFINE TEXTBOX TEXT_1
ROW	 300
COL	 10
VALUE	 'Test'
END TEXTBOX

ON KEY F2 ACTION MsgInfo ( Win_2.FocusedControl, GetControlType(( Win_2.FocusedControl ), 'Win_2') )
ON KEY F3 ACTION Test2('Win_2')

END WINDOW

Center Window Win_1

// Panel windows are automatically activated through its parent
// so, only Win_1 must be activated.

Activate Window Win_1

Return

PROCEDURE Test2(cForm)
LOCAL cFoco, cTipo
cFoco := GetProperty(cForm,'FOCUSEDCONTROL')
cTipo := GETCONTROLTYPE( cFoco, cForm)
MSGINFO( cForm +CRLF+ cFoco +CRLF+ cTipo)
RETURN NIL

Regards
Mustafa
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: which control is in focus?

Post by dragancesu »

Thank you, I need for this form, than one button is for both grid, insert, edit, delete but not in this sample
Attachments
whereisfocus.zip
(55.3 KiB) Downloaded 166 times
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: which control is in focus?

Post by SALINETAS24 »

Hola Drangancesu.., no termino de entender lo que quieres.
No obstante a continuación te paso un trozo de programa que yo utilizo para saber de donde vengo cuando pulso salir, y asi puedo o cerrar el programa o hacer otra cosa.
Espero que te sirva..
Saludos.

Code: Select all

BUTTON TBBT13 	;
				TOOLTIP   IF(nIdioma=1,'Salir','Exit')	;
				PICTURE "HP_CLOSE"  ;
				ACTION ( lNewOk:=.F.,cBton:=GetProperty( ThisWindow.Name, 'FocusedControl') ,lSalir:=.T.,;
						IF(cBton="Get01",Win_PePo.release,ActWin_PePo(0) ) ,;
						IF(cBton="Get01",NIL,lSalir:=.F.) )

Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: which control is in focus?

Post by dragancesu »

I agree that it is not the best example
This is a form with two tables linked by a relation, each has its grid, but the toolbar is one and should "know" to which table it relates
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: which control is in focus?

Post by edk »

A dirty way, but works with keys, toolbar and buttons:

Code: Select all

#include "hmg.ch"

Function Main

Local aRows [20] [3]

_HMG_LastActiveGridIndex := 0

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		DEFINE TOOLBAR ToolBar_1 BUTTONSIZE 30,30 

			BUTTON B_FIND CAPTION "[F2] Find" ACTION ShowLastFocusedGrid()
          
		END TOOLBAR
		
		@ 50,10 GRID Grid_Master ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			ON GOTFOCUS _HMG_LastActiveGridIndex := GetLastActiveControlIndex ();
			EDIT ;
			JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 240,10 GRID Grid_Detail ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 ;
			ON GOTFOCUS _HMG_LastActiveGridIndex := GetLastActiveControlIndex ();
			EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
			JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER }
                	
		@ 440, 10 BUTTON Button_1 CAPTION "Last GRID" ACTION ShowLastFocusedGrid() 
                	
		ON KEY F2 ACTION ShowLastFocusedGrid() 
                	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return


***********************************
Function ShowLastFocusedGrid()
Local i := _HMG_LastActiveGridIndex
Local aCtrlData
IF i > 0 
	aCtrlData := GetControlDataByIndex (i)
	MsgInfo (e"Control name\t: " + aCtrlData [2] + CRLF +;
		    e"Control type\t: " + aCtrlData [1] + CRLF +;
		    e"Form name\t: " + aCtrlData [40] [40], "The last focused grid" )
ENDIF
RETURN
Last edited by edk on Fri Apr 12, 2019 10:46 am, edited 2 times in total.
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: which control is in focus?

Post by dragancesu »

Thank you

ON GOTFOCUS is solve
Post Reply