Page 1 of 1
which control is in focus?
Posted: Wed Apr 10, 2019 9:07 pm
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?
Re: which control is in focus?
Posted: Thu Apr 11, 2019 8:15 am
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
Re: which control is in focus?
Posted: Thu Apr 11, 2019 8:39 am
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
Re: which control is in focus?
Posted: Thu Apr 11, 2019 9:32 am
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
Re: which control is in focus?
Posted: Thu Apr 11, 2019 10:52 am
by dragancesu
Thank you, I need for this form, than one button is for both grid, insert, edit, delete but not in this sample
Re: which control is in focus?
Posted: Thu Apr 11, 2019 5:56 pm
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.) )
Re: which control is in focus?
Posted: Fri Apr 12, 2019 6:55 am
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
Re: which control is in focus?
Posted: Fri Apr 12, 2019 10:09 am
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
Re: which control is in focus?
Posted: Fri Apr 12, 2019 10:37 am
by dragancesu
Thank you
ON GOTFOCUS is solve