How to know the current control?
How to know the current control?
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.
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 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)
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)
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: How to know the current control?
Hi Dutch
Have you tried
oDlg:aControls[1]:SetFocus()
I use this on screens created with a resource editor.
Cheers
Colin
Have you tried
oDlg:aControls[1]:SetFocus()
I use this on screens created with a resource editor.
Cheers
Colin
Re: How to know the current control?
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
#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)
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)
-
- Posts: 77
- Joined: Sun Aug 26, 2007 11:53 pm
Re: How to know the current control?
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.
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.
Re: How to know the current control?
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.
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)
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)
Re: How to know the current control?
Code: Select all
//-- 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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
Re: How to know the current control?
Dear Sambomb,
It doesn't work as expect but I've got the solution as below code now.
Thanks for all ideas.
It doesn't work as expect but I've got the solution as below code now.
Thanks for all ideas.
Code: Select all
#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)
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)
Re: How to know the current control?
Try this...
Code: Select all
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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
Re: How to know the current control?
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.
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
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)
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)
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: How to know the current control?
Dutch,
You can try:
oWndFromHwnd( GetFocus() )
You can try:
oWndFromHwnd( GetFocus() )
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How to know the current control?
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:
Encouraged by your posting, I made a simple program, basically using your logic.
Please compile and see how this works on character, date and numeric gets.
Here, the VK button toggles the VKeyBoard.
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
oGet[1]:bGotFocus := {|| x := 1 }
Code: Select all
#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
//----------------------------------------------------------------------------//
Here, the VK button toggles the VKeyBoard.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: How to know the current control?
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
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)
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)
Re: How to know the current control?
I can did it now.
ShowWindow( hWnd, 0 ) // 0 = WS_HIDE
ShowWindow( hWnd, 9 ) // 9 = WS_RESTORE
Thanks for all kindness help.
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)
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)
Re: How to know the current control?
This code do this: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
For i := 1 to Len(oDlg:aControls) If oDlg:aControls[i]:ClassName() = "TGET" If oDlg:aControls[i]:lFocused //-- Your function exit end end end
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 )
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
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
Re: How to know the current control?
Dear Sambomb,
Thank you so much, I will try your sample again.
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)
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)