Button without focus

Button without focus

Postby souza.fo » Thu Apr 22, 2010 7:37 pm

I need to create a button that appears the number in the Edit / Combo active (focus) and the focus remains on the Edit / As. For example button "1", When I click on this button will display the number 1 in the Edit / Combo active (Just like when using the keyboard Windows Mobile).

thanks,

Fabio Souza
souza.fo
 
Posts: 8
Joined: Thu Apr 22, 2010 1:31 pm

Re: Button without focus

Postby Antonio Linares » Sun Apr 25, 2010 8:31 am

Fabio,

You can give the focus to any control doing:

oControl:SetFocus()

i.e.:

oGet:SetFocus()
regards, saludos

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

Re: Button without focus

Postby Jeff Barnes » Fri Apr 30, 2010 7:54 pm

Hi Fabio,

This might also help. I had to have a larger input screen for numbers in my application.
The code below allows the user to click a number then the focus automatically switches to the next get.


Code: Select all  Expand view  RUN
Function SixBorg(nRecordNum)
   LOCAL nBorg1:=0, nBorg2:=0, oBORG, oSayBorg, cBorgTitle, aBorgItems:={}, oCbx
   LOCAL cBorg1:="", cBorg2:="", oGet1, oGet2, nGetFocus
   Define Dialog oBORG from 5,2 to 20,26 Title "Enter BORG" STYLE nStyle
      @ 0.5,2  say oSayBorg PROMPT "Dyspnea" of oBorg COLOR RGB(0,0,0),RGB(255,255,255) SIZE 25,10
      @ 0.5,9  say oSayBorg PROMPT "Fatigue" of oBorg COLOR RGB(0,0,0),RGB(255,255,255)   SIZE 25,10
      @ 1.5,2 Get oGet1 var nBORG1 of oBORG SIZE 20,10 PICTURE "99.9" UPDATE VALID (nGetFocus :=1,.t.)
      @ 1.5,7 Get oGet2 var nBORG2 of oBORG SIZE 20,10 PICTURE "99.9" UPDATE VALID (nGetFocus :=2,.t.)
       
        @ 3,1   BUTTON oBtn PROMPT "0"   SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=0,oGet2:Setfocus()),(nBorg2:=0,oGet1:SetFocus())),oBorg:Update() )
        @ 3,5   BUTTON oBtn PROMPT "0.5" SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=0.5,oGet2:Setfocus()),(nBorg2:=0.5,oGet1:SetFocus())),oBorg:Update() )
        @ 3,9   BUTTON oBtn PROMPT "1"   SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=1,oGet2:Setfocus()),(nBorg2:=1,oGet1:SetFocus())),oBorg:Update() )
        @ 3,13  BUTTON oBtn PROMPT "2"   SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=2,oGet2:Setfocus()),(nBorg2:=2,oGet1:SetFocus())),oBorg:Update() )

        @ 3.9,1  BUTTON oBtn PROMPT "3"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=3,oGet2:Setfocus()),(nBorg2:=3,oGet1:SetFocus())),oBorg:Update() )
        @ 3.9,5  BUTTON oBtn PROMPT "4"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=4,oGet2:Setfocus()),(nBorg2:=4,oGet1:SetFocus())),oBorg:Update() )
        @ 3.9,9  BUTTON oBtn PROMPT "5"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=5,oGet2:Setfocus()),(nBorg2:=5,oGet1:SetFocus())),oBorg:Update() )
        @ 3.9,13 BUTTON oBtn PROMPT "6"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=6,oGet2:Setfocus()),(nBorg2:=6,oGet1:SetFocus())),oBorg:Update() )

        @ 4.9,1  BUTTON oBtn PROMPT "7"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=7,oGet2:Setfocus()),(nBorg2:=7,oGet1:SetFocus())),oBorg:Update() )
        @ 4.9,5  BUTTON oBtn PROMPT "8"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=8,oGet2:Setfocus()),(nBorg2:=8,oGet1:SetFocus())),oBorg:Update() )
        @ 4.9,9  BUTTON oBtn PROMPT "9"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=9,oGet2:Setfocus()),(nBorg2:=9,oGet1:SetFocus())),oBorg:Update() )
        @ 4.9,13 BUTTON oBtn PROMPT "10"  SIZE 15,15 Action ( iif(nGetFocus=1,(nBorg1:=10,oGet2:Setfocus()),(nBorg2:=10,oGet1:SetFocus())),oBorg:Update() )

      @ 2,6   BUTTON oBtnBorgOK PROMPT "OK" SIZE 25,15 of oBORG ACTION (UpdateSixBORG(nRecordNum, nBorg1, nBorg2),oBORG:End())
      oBORG:Center()
   Activate Dialog oBORG NOMODAL
Return Nil
 
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Button without focus

Postby souza.fo » Mon May 10, 2010 4:24 pm

After searching the forum I found two solutions The first is using a fake __keyboard and the other is manipulating the data with a function. See below:

First Solution with a "fake" __keyboard():
Code: Select all  Expand view  RUN

STATIC oFocusGet

(...)

@ 14,02 Say "Prod:" OF oWndProdutos SIZE 15,7.5 PIXEL
@ 13,17 GET oGetProduto VAR cProduto OF oWndProdutos PICT "@!" SIZE 38,10 PIXEL
oGetProduto:bGotFocus  := {|| oFocusGet := oGetProduto }

(...)

@ 36.5,01 BUTTON oBtn1 PROMPT "1" OF oWndProdutos SIZE 13,11 ACTION ( oFocusGet:SetFocus(), SetStateKey(49, .T.), SetStateKey(49, .F.) )
@ 36.5,16 BUTTON oBtn2 PROMPT "2" OF oWndProdutos SIZE 13,11 ACTION ( oFocusGet:SetFocus(), SetStateKey(49, .T.), SetStateKey(49, .F.) )
@ 36.5,31 BUTTON oBtn2 PROMPT "3" OF oWndProdutos SIZE 13,11 ACTION ( oFocusGet:SetFocus(), SetStateKey(51, .T.), SetStateKey(49, .F.) )

(...)

@ 49,91  BUTTON oBtnBack PROMPT "<-" OF oWndProdutos SIZE 13,11 ACTION ( oGetProduto:SetFocus(), SetStateKey(8, .T.), SetStateKey(8, .F.) )

*************************
#pragma BEGINDUMP

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

HB_FUNC( SETSTATEKEY )
{
  if( hb_parl(2) )
      keybd_event( hb_parvnl(1), 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
  else
      keybd_event( hb_parvnl(1), 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}

#pragma ENDDUMP
 



The Second Solution using a Function:
Code: Select all  Expand view  RUN

STATIC oFocusGet

(...)

@ 14,02 Say "Prod:" OF oWndProdutos SIZE 15,7.5 PIXEL
@ 13,17 GET oGetProduto VAR cProduto OF oWndProdutos PICT "@!" SIZE 38,10 PIXEL
oGetProduto:bGotFocus  := {|| oFocusGet := oGetProduto }

(...)

@ 36.5,01 BUTTON oBtn1 PROMPT "1" OF oWndProdutos SIZE 13,11 ACTION DigVal("1")
@ 36.5,16 BUTTON oBtn2 PROMPT "2" OF oWndProdutos SIZE 13,11 ACTION DigVal("2")
@ 36.5,31 BUTTON oBtn2 PROMPT "3" OF oWndProdutos SIZE 13,11 ACTION DigVal("3")

(...)

@ 49,91  BUTTON oBtnBack PROMPT "<-" OF oWndProdutos SIZE 13,11 ACTION DigVal("<")


STATIC FUNCTION DigVal(cValor)
LOCAL cBuffer

 cBuffer := Alltrim(oGetFocus:cText())

 If cValor == "<"  //Delete
    cBuffer := Alltrim(Substr(cBuffer, 1, oFocusGet:nPos -2) + Substr(cBuffer, oFocusGet:nPos))
 Else
   cBuffer += cValor
 Endif

 oGetFocus:cText(cBuffer)
 oGetFocus:SetFocus()

RETURN .T.
 


Best Regards,

Fabio Souza
souza.fo
 
Posts: 8
Joined: Thu Apr 22, 2010 1:31 pm


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 5 guests