How to know where I am

How to know where I am

Postby jicorral » Fri Mar 06, 2009 10:11 am

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  Expand view
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
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Re: How to know where I am

Postby Antonio Linares » Sat Mar 07, 2009 10:16 am

Jorge Ignacio,

Here you have a working example:
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to know where I am

Postby zazibr » Sat Mar 07, 2009 9:45 pm

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
zazibr
 
Posts: 71
Joined: Mon Jan 28, 2008 11:18 am
Location: Campo Grande,MS, BRASIL

Re: How to know where I am

Postby Antonio Linares » Sun Mar 08, 2009 8:57 am

Daniel,

Aqui lo tienes:
Code: Select all  Expand view
#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
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to know where I am

Postby jicorral » Mon Mar 09, 2009 12:11 pm

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  Expand view
#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 :)
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests