How to know the current control?

How to know the current control?

Postby dutch » 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/]Image
Thanks in advance.
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby Colin Haig » 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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: How to know the current control?

Postby dutch » Mon Sep 06, 2010 2: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: Select all  Expand view
#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 (http://www.FreeVirtualKeyboard.com)" )=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 (http://www.FreeVirtualKeyboard.com)" ) )) SIZE 30,15 PIXEL


ACTIVATE DIALOG oDlg CENTERED ;
     VALID(SendMessage( FindWindow( 0, "Free Virtual Keyboard (http://www.FreeVirtualKeyboard.com)" ), 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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby Jonathan Hodder » Mon Sep 06, 2010 5: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.
Jonathan Hodder
 
Posts: 77
Joined: Sun Aug 26, 2007 11:53 pm

Re: How to know the current control?

Postby dutch » Thu Sep 09, 2010 6: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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby sambomb » Thu Sep 09, 2010 7:40 pm

Code: Select all  Expand view

   //-- 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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: How to know the current control?

Postby dutch » Thu Sep 09, 2010 7: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: Select all  Expand view
#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 (www.FreeVirtualKeyboard.com)" )=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 (www.FreeVirtualKeyboard.com)" ) )) SIZE 30,15 PIXEL


ACTIVATE DIALOG oDlg CENTERED ;
     VALID(SendMessage( FindWindow( 0, "Free Virtual Keyboard (www.FreeVirtualKeyboard.com)" ), 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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby sambomb » Fri Sep 10, 2010 4:36 pm

Try this...
Code: Select all  Expand view

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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: How to know the current control?

Postby dutch » 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: Select all  Expand view

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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby Antonio Linares » Sat Sep 11, 2010 7:54 am

Dutch,

You can try:

oWndFromHwnd( GetFocus() )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41406
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to know the current control?

Postby nageswaragunupudi » Sat Sep 11, 2010 2: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: Select all  Expand view
oGet[1]:bGotFocus := {|| x := 1 }


Encouraged by your posting, I made a simple program, basically using your logic.
Code: Select all  Expand view
#include 'fivewin.ch'

#define VK_TITLE "Free Virtual Keyboard (www.FreeVirtualKeyboard.com)"

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

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
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to know the current control?

Postby dutch » Sun Sep 12, 2010 8: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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby dutch » Mon Sep 13, 2010 4: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 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to know the current control?

Postby sambomb » 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: Select all  Expand view

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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: How to know the current control?

Postby dutch » Thu Sep 16, 2010 2:15 am

Dear Sambomb,

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

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 37 guests