Page 1 of 1
How to know where I am
Posted: Fri Mar 06, 2009 10:11 am
by jicorral
I have a key action defined for the application. How can I know the context, the window, dialog and control where is pressed?
Code: Select all
static oWnd
function Main()
SetKey( VK_F2, { | cProc, nLine, cVar, x | Donde(cProc, nLine, cVar, x) } )
...
function Donde(cProc, nLine, cVar, x)
...
return nil
I don't want to define the key action for each window, dialog, folder, control. I've been trying with
oWnd:oCtlFocus but always be empty.
Re: How to know where I am
Posted: Sat Mar 07, 2009 10:16 am
by Antonio Linares
Jorge Ignacio,
Here you have a working example:
Code: Select all
#include "FiveWin.ch"
function Main()
SetKey( VK_F2, { || WhereAmI() } )
Another()
return nil
function Another()
local oDlg, cTest := Space( 20 )
DEFINE DIALOG oDlg TITLE "Test"
@ 1.5, 5 GET cTest
@ 3, 10 BUTTON "Ok"
ACTIVATE DIALOG oDlg CENTERED
return nil
function WhereAmI()
local oCtrl := oWndFromHwnd( GetFocus() )
MsgInfo( "ProcName: " + ProcName( 11 ) + CRLF + ;
"ProcLine: " + Str( ProcLine( 11 ) ) + CRLF + ;
"Focused object: " + oCtrl:ClassName() + CRLF + ;
"Dialog title: " + oCtrl:oWnd:GetText() )
return nil
Re: How to know where I am
Posted: Sat Mar 07, 2009 9:45 pm
by zazibr
olá antonio poderia criar o mesmo exemplo acima so que utilizando txbrowse ?
obrigado
Re: How to know where I am
Posted: Sun Mar 08, 2009 8:57 am
by Antonio Linares
Daniel,
Aqui lo tienes:
Code: Select all
#include "FiveWin.ch"
#include "XBrowse.ch"
function Main()
SetKey( VK_F2, { || WhereAmI() } )
Another()
return nil
function Another()
local oDlg, oBrw, oCol
USE Customer
DEFINE DIALOG oDlg TITLE "Test"
@ 0, 0 XBROWSE oBrw OF oDlg ALIAS "Customer"
oCol = oBrw:AddCol()
oCol:bStrData = { || Customer->First }
oCol:cHeader = "First"
oBrw:CreateFromCode()
oDlg:oClient = oBrw
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT oDlg:Resize()
return nil
function WhereAmI()
local oCtrl := oWndFromHwnd( GetFocus() )
MsgInfo( "ProcName: " + ProcName( 11 ) + CRLF + ;
"ProcLine: " + Str( ProcLine( 11 ) ) + CRLF + ;
"Focused object: " + oCtrl:ClassName() + CRLF + ;
"Dialog title: " + oCtrl:oWnd:GetText() )
return nil
Re: How to know where I am
Posted: Mon Mar 09, 2009 12:11 pm
by jicorral
Ok. Thank you. It's working getting the correct ID of the window, dialog or control but now I have a new problem:
the nHelpID of the controls is missing. I have defined nHelpID for the window, the dialogs and the controls. when ask for oCtrl:nHelpID in case of windows or dialogs I get the correct one but with controls I always get NIL. Any idea?
Antonio Linares wrote:Jorge Ignacio,
Here you have a working example:
Code: Select all
#include "FiveWin.ch"
...
function WhereAmI()
local oCtrl := oWndFromHwnd( GetFocus() )
MsgInfo( "ProcName: " + ProcName( 11 ) + CRLF + ;
"ProcLine: " + Str( ProcLine( 11 ) ) + CRLF + ;
"Focused object: " + oCtrl:ClassName() + CRLF + ;
"Dialog title: " + oCtrl:oWnd:GetText() )
return nil