How to know where I am

Post Reply
User avatar
jicorral
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am
Contact:

How to know where I am

Post 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.
Jorge Ignacio Corral
Enjoy it :)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to know where I am

Post 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   
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
zazibr
Posts: 71
Joined: Mon Jan 28, 2008 11:18 am
Location: Campo Grande,MS, BRASIL

Re: How to know where I am

Post by zazibr »

olá antonio poderia criar o mesmo exemplo acima so que utilizando txbrowse ?

obrigado
Daniel Lopes Filho - Campo Grande,MS,Brasil
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6693) + gtwvw + fw 10.2 + vsx e
fw pcc (ainda não usei)
msn : zazibr@hotmail.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to know where I am

Post 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   
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
jicorral
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am
Contact:

Re: How to know where I am

Post 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   
 
Jorge Ignacio Corral
Enjoy it :)
Post Reply