Setting the focus to any object

Post Reply
User avatar
Maurilio Viana
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil
Contact:

Setting the focus to any object

Post 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
manuramos
Posts: 219
Joined: Mon Dec 26, 2005 7:25 pm
Location: Jerez de la Frontera (Spain)

Post 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)
Nos Gusta Programar
Post Reply