Page 1 of 1

Setting the focus to any object

Posted: Fri Feb 23, 2007 12:19 pm
by Maurilio Viana
Many questions are posted in FW's forums related to focus.
When oObj:Setfocus() fail, I use this function that work fine for me for many yeara (FW+Clipper / FW+Harbour / FW+xHarbour):

Code: Select all

function xSetFocus(oObj)
 local oTime

 define timer oTime interval 10 of oObj:oWnd ;
        action (oObj:SetFocus(), oTime:DeActivate())
 activate timer oTime
return Nil
You can call:
xSetFocus( oGet )
xSetFocus( oButton )
xSetfocus( oLbx )

But... in any misterious cases xSetFocus() fail. Then you can call it twice or create a function as below:

Code: Select all

function xFocus(oObj)
 xSetFocus(oObj) 
 xSetFocus(oObj) 
return Nil
You can call the same way xSetFocus():
xFocus( oGet )
xFocus( oBtn )
...

Best regards,
Maurilio

Posted: Mon Feb 26, 2007 8:20 pm
by manuramos
I prefer:

PostMessage( oObj:hWnd,FM_CHANGEFOCUS) or
SendMessage( oObj:hWnd,FM_CHANGEFOCUS) or
PostMessage( oObj:hWnd,FW_SETFOCUS) or
SendMessage( oObj:hWnd,FW_SETFOCUS)

Depending the situation. SendMessage is inmediate, PostMessage waits at the end of the Commands queu. FM_CHANGEFOCUS seems to be more efective and permanent than the other one (I don't know why).

PostMessage is very good for VALID's clauses.

You can even use it out of any objects/dialogs.

Another very good constant is WM_CLOSE, for example to close a dialog from anywhere.

(Excuse my english)