Page 1 of 1

:SetFocus problem with WHEN clause in Gets and Pushbuttons

Posted: Fri Nov 10, 2006 11:45 am
by RAMESHBABU
I have a problem with :SetFocus()

In the following code I have three gets and three pushbuttons.

By default the Gets are disabled and when the "Create" button
is pressed, the gets should be enabled and the focus should be
placed on the 1st get. The "Create" and "Save" functions of my
code below is working Ok enabling and disabling the gets.

But the oGet1:SetFocus() in Create() function and oBtn1:SetFocus()
in Save() function are not working at all.

I tried with oDlg:Update() and oDlg:Refresh() also in both Create()
and Save() functions without sucess.

Can anybody look into the code and suggest me where I am going
wrong?

I am using FWH 2.8 (September Build) + xHarbour 0.99.61 (Simplex)

Thanks

- Ramesh Babu P

Code: Select all

#include "fivewin.ch"

FUNCTION main()

LOCAL oDlg, oGet1, oGet2, oGet3, oBtn1, oBtn2, oBtn3, cGet1, cGet2, cGet3
LOCAL lCreate := .T., lSave := .F., lGo := .F.

STORE SPACE(30) TO cGet1, cGet2, cGet3

DEFINE DIALOG oDlg RESOURCE "TESTFOCUS"

REDEFINE GET oGet1 VAR cGet1 ID 101 OF oDlg UPDATE WHEN lGo 
REDEFINE GET oGet2 VAR cGet2 ID 102 OF oDlg UPDATE WHEN lGo 
REDEFINE GET oGet3 VAR cGet3 ID 103 OF oDlg UPDATE WHEN lGo 

REDEFINE BUTTON oBtn1 ID 104 OF oDlg WHEN lCreate ;
         UPDATE ACTION Create(@lCreate,@lSave,@lGo,@oGet1)

REDEFINE BUTTON oBtn2 ID 105 OF oDlg WHEN lSave   ;
         UPDATE ACTION Save(@lCreate,@lSave,@lGo,@oBtn1)

REDEFINE BUTTON oBtn3 ID 106 OF oDlg ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED ON INIT oBtn1:SetFocus()

RETURN nil

**********

FUNCTION Create(lCreate, lSave, lGo, oGet1)

lSave   := .T.
lCreate := .F.
lGo     := .T.

oGet1:SetFocus()

RETURN nil

**********

FUNCTION Save(lCreate, lSave, lGo, oBtn1)

lSave   := .F.
lCreate := .T.
lGo     := .F.

oBtn1:SetFocus()

RETURN nil

**********

/****************************************************************************
get.rc
produced by Borland Resource Workshop
*****************************************************************************/

TESTFOCUS DIALOG 6, 15, 207, 113
STYLE DS_MODALFRAME | 0x4L | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Testing Focus"
FONT 8, "MS Sans Serif"
{
 GROUPBOX "", 301, 8, 3, 192, 82, BS_GROUPBOX
 LTEXT "Get - 1", -1, 20, 23, 30, 8
 EDITTEXT 101, 58, 20, 132, 13
 LTEXT "Get - 2", -1, 19, 44, 30, 8
 EDITTEXT 102, 58, 41, 132, 13
 LTEXT "Get - 3", -1, 19, 65, 30, 8
 EDITTEXT 103, 58, 62, 132, 13
 PUSHBUTTON "&Create", 104, 74, 92, 40, 15
 PUSHBUTTON "&Save", 105, 117, 92, 40, 15
 PUSHBUTTON "&Ok", 106, 160, 92, 40, 15
}


Posted: Fri Nov 10, 2006 12:00 pm
by Antonio Linares
Ramesh,

Try this:

oGet1:PostMsg( WM_SETFOCUS ) instead of oGet1:SetFocus()

Posted: Fri Nov 10, 2006 12:17 pm
by RAMESHBABU
Mr.Antonio

Amazing to get a solution in 5 minues time.

It is working now Ok.

Thank you very much.

BTW, why :SetFocus() is not working!

Regards to you

- Ramesh Babu P

Posted: Fri Nov 10, 2006 1:51 pm
by RAMESHBABU
Hi Mr.Antonio

Once the focus is passed on to a get with oGet1:PostMsg(EM_SETFOCUS)
and when I click on any other controls or press tab, the blinking cursor is
still showing on old control (oGet1) and bLostFocus is also not working
properly.

Just add the following lines to the above code after redefinition of GETS,
implement the oGet1:SetFocus(WM_SETFOCUS) in place of
oGet1:SetFocus(), oBtn1:SetFocus(WM_SETFOCUS) in place of
oBtn1:SetFocus() and test it. You will find the anomaly.

Code: Select all

oGet1:bGotFocus  := {||oGet1:SetColor(nRGB(0,0,0), nRGB(193,193,255))}
oGet1:bLostFocus := {||oGet1:SetColor(nRGB(0,0,0), nRGB(255,255,255))}
Thanks to you

- Ramesh Babu P

Posted: Fri Nov 10, 2006 1:55 pm
by Antonio Linares
Ramesh,

Try this:

oGet1:PostMsg( WM_SETFOCUS )
oBtn1:oJump = oGet1

Posted: Fri Nov 10, 2006 1:59 pm
by Antonio Linares
Ramesh,

> BTW, why :SetFocus() is not working

Because Windows returns the focus to the button, after processing the ACTION of the button, so we can not interrupt that process.

Posted: Fri Nov 10, 2006 2:07 pm
by RAMESHBABU
Hello Mr.Antonio

Thanks again for immediate attention.
oBtn1:oJump = oGet1
If we do not know in advance that the user will jump to oGet1 from oBtn1?

Thanks

Ramesh Babu P

Posted: Fri Nov 10, 2006 2:10 pm
by Antonio Linares
Ramesh,

> If we do not know in advance that the user will jump to oGet1 from oBtn1?

You set it from the Create() function where you know where it will go.

Posted: Fri Nov 10, 2006 2:21 pm
by RAMESHBABU
Mr.Antonio

Kindly test the above code with the changes you have suggested
and give me the suitable solution please.

I tried with the all your suggestions with fail.

Regards to you

- Ramesh Babu P

Posted: Mon Nov 13, 2006 9:28 am
by Antonio Linares
Ramesh,

Code: Select all

FUNCTION Create(lCreate, lSave, lGo, oGet1 ) 

lSave   := .T. 
lCreate := .F. 
lGo     := .T. 

oGet1:PostMsg( WM_LBUTTONDOWN )
oGet1:PostMsg( WM_LBUTTONUP )

RETURN nil 

Posted: Tue Nov 14, 2006 2:16 am
by RAMESHBABU
Mr.Antonio

Thank you very much for your reply.

After spending some time on this, I could get the
required effect with the following statement.
oGet1:PostMsg( WM_RBUTTONDOWN )
Regards to you

- Ramesh Babu P