Page 1 of 2

SetFocus problem

Posted: Fri Feb 24, 2006 9:11 am
by Gianni
With this little example you can see that if I push "OK" button with mouse all works, if I push "ALT O" on keyboard all works, if I focus on "OK" and push "SPACE BAR" all works, but if I push "RETURN", focus goes on next control instead in "address".
I have FWH 2.7 feb 2006

Thank in advance
Gianni

Code: Select all

#include "FiveWin.ch"

function Main()
   local oDlg
   local lFivePro  := .T.
   local lDialog   := .T.
   local lObjects  := .F.
   local nNivel    := 1
   local cName     := SPACE( 10 )
   local cAddress  := SPACE( 30 )
   local oBtn, oGet1, oGet2

   DEFINE DIALOG oDlg FROM 8, 2 TO 25, 50 TITLE "SetFocus test"

   @ 1,  1 SAY "&Name:" OF oDlg
   @ 1,  6 GET oGet1 VAR cName OF oDlg
   @ 2,  1 SAY "&Address:" OF oDlg
   @ 2,  6 GET oGet2 VAR cAddress OF oDlg

   @ 3,  1 TO 7, 8 LABEL "&Products" OF oDlg
   @ 4,  2 CHECKBOX lFivePro PROMPT "&FivePro" OF oDlg
   @ 5,  2 CHECKBOX lDialog  PROMPT "&Dialog"  OF oDlg
   @ 6,  2 CHECKBOX lObjects PROMPT "O&bjects" OF oDlg

   @ 3,  9 TO 7, 17 LABEL "&Nivel" OF oDlg
   @ 4,  9 RADIO nNivel PROMPT "&Novice", "A&vanced", "&Expert" OF oDlg

   @ 6,  3 BUTTON oBtn PROMPT "&Ok"  OF oDlg SIZE 50, 12 ACTION (oGet2:ctext("OK ACTION RUN ON " + TIME()),oGet2:SetFocus()) DEFAULT

   @ 6, 15 BUTTON "&Cancel" OF oDlg SIZE 50, 12 ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

return nil

Re: SetFocus problem

Posted: Fri Feb 24, 2006 10:36 am
by Enrico Maria Giordano
Try this:

Code: Select all

@ 6,  3 BUTTON oBtn PROMPT "&Ok"  OF oDlg SIZE 50, 12 ACTION (oGet2:ctext("OK ACTION RUN ON " + TIME()), oGet2:PostMsg(WM_SETFOCUS)) DEFAULT


EMG

Posted: Fri Feb 24, 2006 11:19 am
by Gianni
Thank for answer but don't works. With "POSTMSG(WM_SETFOCUS)" it makes something strange, because I see the cursor in the get but the "real" focus is in some other control.

Regards
Gianni

Posted: Fri Feb 24, 2006 1:15 pm
by James Bott
Try adding a oGet2:refresh() after the oGet2:setFocus().

James

Posted: Fri Feb 24, 2006 3:38 pm
by Gianni
James,
many thank for reply but still don't works.

Regards
Gianni

Posted: Fri Feb 24, 2006 5:07 pm
by Gale FORd
I think you need to add an :oJump
Try this:

@ 6, 3 BUTTON oBtn PROMPT "&Ok" OF oDlg SIZE 50, 12 ACTION (oGet2:ctext("OK ACTION RUN ON " + TIME()),oBtn:oJump := oGet2, oGet2:SetFocus()) DEFAULT

Posted: Fri Feb 24, 2006 5:15 pm
by Gianni
Gale,
thanks but don't works.

Regards
Gianni

Posted: Fri Feb 24, 2006 8:52 pm
by Enrico Maria Giordano
Try this:

Code: Select all

   @ 6,  3 BUTTON oBtn PROMPT "&Ok"  OF oDlg SIZE 50, 12 ACTION ( oGet2:ctext("OK ACTION RUN ON " + TIME()),;
                                                                  oBtn:SetFocus(),;
                                                                  SysRefresh(),;
                                                                  oGet2:SetFocus() ) DEFAULT
EMG

Try this

Posted: Sat Feb 25, 2006 1:00 am
by grumpy
Change
@ 2, 6 GET oGet2 VAR cAddress OF oDlg

to

@ 2, 6 GET oGet2 VAR cAddress OF oDlg UPDATE

and
@ 6, 3 BUTTON oBtn PROMPT "&Ok" OF oDlg SIZE 50, 12 ACTION (oGet2:ctext("OK ACTION RUN ON " + TIME()),oGet2:SetFocus()) DEFAULT

to

@ 6, 3 BUTTON oBtn PROMPT "&Ok" OF oDlg SIZE 50, 12 ACTION (cAddress := "OK ACTION RUN ON " + TIME(),oGet2:Refresh(), oGet2:SetFocus(), Sysrefresh()) DEFAULT

Posted: Sat Feb 25, 2006 9:45 am
by Gianni
Grumpy,
thanks you too but don't works.

Regards
Gianni

Posted: Sat Feb 25, 2006 9:55 am
by Gianni
EnricoMaria,
thanks you, know it almost works!
There is still only one case that don't works and it is when I push "RETURN" when focus is already on "OK" button. In this case focus goes on "CANCEL" button!!! :shock:
Don't you think is a FWH bug? I think that even your code almost works, it is a work around.

Regards
Gianni

Posted: Sat Feb 25, 2006 10:02 am
by Enrico Maria Giordano
No, I think that it is your design that is wrong.

EMG

Posted: Sat Feb 25, 2006 4:34 pm
by Gianni
EMG,
I don't understand what's wrong in my design.
I only need that a get take focus after a keyboard RETURN.
What's wrong in it?
SETFOCUS will be ignored when I use RETURN key. If I use another way ( mouse or SPACE or accelerator) all works. This different behaviour make me to think that it is a bug even my design was wrong.

Regards
Gianni

Posted: Sat Feb 25, 2006 10:18 pm
by Enrico Maria Giordano
Sorry, I would have to say "perhaps". Anyway, this is a sample that solves the last problem:

Code: Select all

   @ 6,  3 BUTTON oBtn PROMPT "&Ok"  OF oDlg SIZE 50, 12 ACTION ( oGet2:ctext("OK ACTION RUN ON " + TIME()),;
                                                                  oGet2:SetFocus(),;
                                                                  SysRefresh(),;
                                                                  oGet2:SetFocus() ) DEFAULT
EMG

Posted: Mon Feb 27, 2006 8:47 am
by Gianni
EMG,
many thanks, now it works!!!

Gianni