SetFocus problem

Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

SetFocus problem

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: SetFocus problem

Post 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
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Try adding a oGet2:refresh() after the oGet2:setFocus().

James
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post by Gianni »

James,
many thank for reply but still don't works.

Regards
Gianni
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post 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
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post by Gianni »

Gale,
thanks but don't works.

Regards
Gianni
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
grumpy
Posts: 48
Joined: Tue Dec 27, 2005 12:40 pm
Location: Australia

Try this

Post 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
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post by Gianni »

Grumpy,
thanks you too but don't works.

Regards
Gianni
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post 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
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
Gianni
Posts: 30
Joined: Fri Oct 07, 2005 6:58 am

Post by Gianni »

EMG,
many thanks, now it works!!!

Gianni
Post Reply