FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to know the current control?
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
How to know the current control?
Posted: Sun Sep 05, 2010 10:42 PM
I gonna use Keyboard on screen (FreeVK) but I would like to know the current control. How do I get the object for the current control?

I would like to press KB button and send focus to 1st GET. How do I do?
[URL=http://img713.imageshack.us/i/testkb.jpg/]
Thanks in advance.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: How to know the current control?
Posted: Sun Sep 05, 2010 11:26 PM

Hi Dutch

Have you tried

oDlg:aControls[1]:SetFocus()

I use this on screens created with a resource editor.

Cheers

Colin

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Mon Sep 06, 2010 02:52 AM
Thanks Colin, it doesn't work. It will not focus to any TGET. This is my sample, I need to activate keyboard in any TGET (as user requirement) but I don't need to activate since start TDIALOG bcos sometime the user don't need it, like Google Search. It has keyboard on screen, if any.
Code (fw): Select all Collapse
#include 'fivewin.ch'

*--------------------*
Procedure main
local oDlg, oGet[2], oBtn
local cVar1, cVar2, x
local hCalc   // := CreateProcess( "FreeVK" )

x:=1 
cVar1 := space(100)
cVar2 := space(100)
DEFINE DIALOG oDlg FROM 0, 0 TO 200, 400 TITLE 'Test Virtual Keyboard' PIXEL

@ 10, 10 SAY 'Test Get ' OF oDlg PIXEL SIZE 30,12
@  8, 45 GET oGet[1] VAR cVar1 OF oDlg SIZE 60,12 PIXEL 
    oGet[1]:bGotFocus := {|| x := 1 }

@ 30, 10 SAY 'Test Get ' OF oDlg PIXEL SIZE 30,12
@ 28, 45 GET oGet[2] VAR cVar2 OF oDlg SIZE 60,12 PIXEL 
    oGet[2]:bGotFocus := {|| x := 2 }

@ 50, 10 BUTTON oBtn PROMPT 'KB' ACTION (oDlg:aControls[1]:SetFocus(), hCalc := CreateProcess( "FreeVK" )) SIZE 30,15 PIXEL

// @ 50, 10 BUTTON oBtn PROMPT 'KB' ACTION (if( FindWindow( 0, "Free Virtual Keyboard (<!-- m --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">http://www.FreeVirtualKeyboard.com</a><!-- m -->)" )=0,ShellExecute(0, "Open", "FreeVK.EXE"),)) SIZE 30,15 PIXEL

@ 50, 50 BUTTON oBtn PROMPT 'End KB' ACTION (TerminateProcess( hCalc ), hCalc := 0) SIZE 30,15 PIXEL

@ 50, 90 BUTTON oBtn PROMPT 'Show KB' ACTION (MsgInfo( hCalc )) SIZE 30,15 PIXEL


// @ 50, 50 BUTTON oBtn PROMPT 'Show KB' ACTION (MsgInfo( FindWindow( 0, "Free Virtual Keyboard (<!-- m --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">http://www.FreeVirtualKeyboard.com</a><!-- m -->)" ) )) SIZE 30,15 PIXEL


ACTIVATE DIALOG oDlg CENTERED ;
     VALID(SendMessage( FindWindow( 0, "Free Virtual Keyboard (<!-- m --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">http://www.FreeVirtualKeyboard.com</a><!-- m -->)" ), WM_CLOSE ),.T.)

// VALID (TerminateProcess( hCalc ), .T.)


return 

Function ShowKb
return nil


#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( CREATEPROCESS )
{
   STARTUPINFO StartupInfo;
   PROCESS_INFORMATION ProcessInfo;
   DWORD dwExitCode;

   memset( ( char * ) &StartupInfo, 0, sizeof( STARTUPINFO ) );
   StartupInfo.cb = sizeof( StartupInfo );
   StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow = ( hb_pcount() > 1 ) ? hb_parni( 2 ) : SW_SHOWNA;
   CreateProcess( 0, ( char * ) hb_parc( 1 ), 0, 0, FALSE,
                  CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS,
                  0, 0, &StartupInfo, &ProcessInfo );
   hb_retnl( ( LONG ) ProcessInfo.hProcess );                                 
}

HB_FUNC( TERMINATEPROCESS )
{
   hb_retl( TerminateProcess( ( HANDLE ) hb_parnl( 1 ), hb_parnl( 2 ) ) );
}   

#pragma ENDDUMP
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 77
Joined: Sun Aug 26, 2007 11:53 PM
Re: How to know the current control?
Posted: Mon Sep 06, 2010 05:37 AM

Maybe try

AEVAL(oDlg:aControls,{|oControl,nnumber| iif(UPPER(oControl:ClassName())='TGET',MsgInfo(nnumber),nil) } )

This should list the control number/s with the 'TGet' class if this is what you are trying to obtain.

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Thu Sep 09, 2010 06:47 PM

Dear Jonathan,

Thank for your reply but it show the number of control which is TGET. But I need to know the current active control (bGotFocus) as the example image, it should know the 1st TGet control has focus.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: How to know the current control?
Posted: Thu Sep 09, 2010 07:40 PM
Code (fw): Select all Collapse
   //-- Loop to know if a Get is focused
   For i := 1 to Len(oGet)
      //-- Stop on the focused 
      if oGet[i]:lFocused
         //-- Your function goes here
         exit
      end
   end
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Thu Sep 09, 2010 07:53 PM
Dear Sambomb,

It doesn't work as expect but I've got the solution as below code now.

Thanks for all ideas.
Code (fw): Select all Collapse
#include 'fivewin.ch'

*--------------------*
Procedure main
local oDlg, oGet[2], oBtn, oBtns
local cVar1, cVar2, x
local hCalc   // := CreateProcess( "FreeVK" )

x:=1 
cVar1 := space(100)
cVar2 := space(100)
DEFINE DIALOG oDlg FROM 0, 0 TO 200, 400 TITLE 'Test Virtual Keyboard' PIXEL

@ 10, 10 SAY 'Test Get ' OF oDlg PIXEL SIZE 30,12
@  8, 45 GET oGet[1] VAR cVar1 OF oDlg SIZE 60,12 PIXEL 
    oGet[1]:bGotFocus := {|| x := 1 }

@ 30, 10 SAY 'Test Get ' OF oDlg PIXEL SIZE 30,12
@ 28, 45 GET oGet[2] VAR cVar2 OF oDlg SIZE 60,12 PIXEL 
    oGet[2]:bGotFocus := {|| := 2 }

// @ 50, 10 BUTTON oBtn PROMPT 'KB' ACTION (oDlg:aControls[1]:SetFocus(), hCalc := CreateProcess( "FreeVK" )) SIZE 30,15 PIXEL

@ 50, 10 BUTTON oBtn PROMPT 'KB' ACTION (if( FindWindow( 0, "Free Virtual Keyboard (<!-- w --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">www.FreeVirtualKeyboard.com</a><!-- w -->)" )=0,(ShellExecute(0, "Open", "FreeVK.EXE")),), oGet[x]:SetFocus()) SIZE 30,15 PIXEL

// @ 50, 50 BUTTON oBtn PROMPT 'End KB' ACTION (TerminateProcess( hCalc ), hCalc := 0) SIZE 30,15 PIXEL

@ 50, 90 BUTTON oBtns PROMPT 'Show KB' ACTION (msginfo( x )) SIZE 30,15 PIXEL

// @ 50, 50 BUTTON oBtn PROMPT 'Show KB' ACTION (MsgInfo( FindWindow( 0, "Free Virtual Keyboard (<!-- w --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">www.FreeVirtualKeyboard.com</a><!-- w -->)" ) )) SIZE 30,15 PIXEL


ACTIVATE DIALOG oDlg CENTERED ;
     VALID(SendMessage( FindWindow( 0, "Free Virtual Keyboard (<!-- w --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">www.FreeVirtualKeyboard.com</a><!-- w -->)" ), WM_CLOSE ),.T.)

// VALID (TerminateProcess( hCalc ), .T.)


return 

Function ShowKb
return nil

Function GetChk( oGet )
local i
//-- Loop to know if a Get is focused
   For i := 1 to Len(oGet)
      //-- Stop on the focused 
      if oGet[i]:lFocused
         //-- Your function goes here
         exit
      end
   end
return i

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( CREATEPROCESS )
{
   STARTUPINFO StartupInfo;
   PROCESS_INFORMATION ProcessInfo;
   DWORD dwExitCode;

   memset( ( char * ) &StartupInfo, 0, sizeof( STARTUPINFO ) );
   StartupInfo.cb = sizeof( StartupInfo );
   StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow = ( hb_pcount() > 1 ) ? hb_parni( 2 ) : SW_SHOWNA;
   CreateProcess( 0, ( char * ) hb_parc( 1 ), 0, 0, FALSE,
                  CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS,
                  0, 0, &StartupInfo, &ProcessInfo );
   hb_retnl( ( LONG ) ProcessInfo.hProcess );                                 
}

HB_FUNC( TERMINATEPROCESS )
{
   hb_retl( TerminateProcess( ( HANDLE ) hb_parnl( 1 ), hb_parnl( 2 ) ) );
}   

#pragma ENDDUMP
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: How to know the current control?
Posted: Fri Sep 10, 2010 04:36 PM
Try this...
Code (fw): Select all Collapse
For i := 1 to Len(oDlg:aControls)
    If oDlg:aControls[i]:ClassName() = "TGET"
        If oDlg:aControls[i]:lFocused
            //-- Your function
            exit
        end
    end
end
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Fri Sep 10, 2010 11:24 PM
Dear Sambomb,

I use (KB) button to get the current focus control but your example alway return 7 (total control in dialog +1). It cannot find the focus control.
sambomb wrote:Try this...
Code (fw): Select all Collapse
For i := 1 to Len(oDlg:aControls)
    If oDlg:aControls[i]:ClassName() = "TGET"
        If oDlg:aControls[i]:lFocused
            //-- Your function
            exit
        end
    end
end
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to know the current control?
Posted: Sat Sep 11, 2010 07:54 AM

Dutch,

You can try:

oWndFromHwnd( GetFocus() )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to know the current control?
Posted: Sat Sep 11, 2010 02:07 PM
Mr. Duch

By the time the VK button is pressed, the previous active get already lost focus, and any logic you use to find the focused control, the result is the VK button.

For this application the best possible logic is what you adopted:
Code (fw): Select all Collapse
oGet[1]:bGotFocus := {|| x := 1 }


Encouraged by your posting, I made a simple program, basically using your logic.
Code (fw): Select all Collapse
#include 'fivewin.ch'

#define VK_TITLE "Free Virtual Keyboard (<!-- w --><a class="postlink" href="http://www.FreeVirtualKeyboard.com">www.FreeVirtualKeyboard.com</a><!-- w -->)"

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oFont
   local oGet, nPos     // save current get and cursor position
   local cVar1    := PadR( "First Get",  80 )
   local cVar2    := PadR( "Second Get", 80 )
   local nVar     := 123456.89
   local dVar     := Date()

   SET DATE BRITISH
   SET CENTURY ON

   SetGetColorFocus()
   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 300,200 PIXEL FONT oFont

   @ 10, 10 GET cVar1 SIZE 130,12 PIXEL OF oDlg
   @ 24, 10 GET cVar2 SIZE 130,12 PIXEL OF oDlg
   @ 38, 10 GET nVar  PICTURE '999,999.99' SIZE  50,12 PIXEL OF oDlg RIGHT
   @ 38, 90 GET dVar  SIZE  50,12 PIXEL OF oDlg

   AEval( oDlg:aControls, { |oCtrl| oCtrl:bGotFocus := { |o| oGet := o } } )

   @ 80, 10 BUTTON "VK" SIZE 40,12 PIXEL OF oDlg ;
      ACTION ( nPos  := oGet:nPos, ToggleVK(), ReFocusGet( oGet, nPos ) )

   ACTIVATE DIALOG oDlg CENTERED
   PostMessage( VkWnd(), WM_CLOSE )
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

static function ToggleVK()

   local hVK    := VkWnd()

   if Empty( hVK )
      WinExec( "FreeVK.Exe" )
   elseif IsIconic( hVK ) .or. ! IsWindowVisible( hVK )
      ShowWindow( hVK, 8 ) // sHOW NORMAL
   else
      ShowWindow( hVK, 0 ) // HIDE
   endif

return nil

//----------------------------------------------------------------------------//

static function VkWnd()

   static hWndVK  := 0

   if ! IsWindow( hWndVK )
      hWndVK   := FindWindow( 0, VK_TITLE )
   endif

return hWndVK

//----------------------------------------------------------------------------//

static function ReFocusGet( oGet, nPos )

   oGet:SetFocus()   // for character gets, this is enough
   if oGet:oGet:Type != 'C'
      oGet:SetPos( nPos )
      if oGet:oGet:Type == 'N' .and. nPos > 1
         oGet:KeyDown( VK_LEFT )
         oGet:KeyDown( VK_RIGHT )
      endif
   endif

return nil

//----------------------------------------------------------------------------//

Please compile and see how this works on character, date and numeric gets.
Here, the VK button toggles the VKeyBoard.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Sun Sep 12, 2010 08:57 AM

Dear Rao,

Your examples is working perfect but I have another question.

How can I use "MINIMIZED" with PostMessage() .or. ;
How can I Minimized external program?

Thanks

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Mon Sep 13, 2010 04:47 AM

I can did it now.
ShowWindow( hWnd, 0 ) // 0 = WS_HIDE
ShowWindow( hWnd, 9 ) // 9 = WS_RESTORE

Thanks for all kindness help.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: How to know the current control?
Posted: Mon Sep 13, 2010 11:42 AM
dutch wrote:Dear Sambomb,

I use (KB) button to get the current focus control but your example alway return 7 (total control in dialog +1). It cannot find the focus control.
sambomb wrote:Try this...
Code (fw): Select all Collapse
For i := 1 to Len(oDlg:aControls)
    If oDlg:aControls[i]:ClassName() = "TGET"
        If oDlg:aControls[i]:lFocused
            //-- Your function
            exit
        end
    end
end


This code do this:
Check all controls in a dialog(named oDlg ...)
If some of the controls is a Get AND that control is focused than you can call your function in the "//-- Your function here", if you need to use the control focused you can use the control as a parameter. Ex: YourFunction( oDlg:aControls[i] )
Maybe you are calling the function after the For and with no Get in focus, so the "i" will return Len() +1
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to know the current control?
Posted: Thu Sep 16, 2010 02:15 AM

Dear Sambomb,

Thank you so much, I will try your sample again.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)