FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Utilities / Utilidades Setting the focus to any object
Posts: 252
Joined: Tue Oct 25, 2005 02:48 PM

Setting the focus to any object

Posted: Fri Feb 23, 2007 12:19 PM
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):

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:

function xFocus(oObj)
 xSetFocus(oObj) 
 xSetFocus(oObj) 
return Nil


You can call the same way xSetFocus():
xFocus( oGet )
xFocus( oBtn )
...

Best regards,
Maurilio
Posts: 219
Joined: Mon Dec 26, 2005 07:25 PM

Setting the focus to any object

Posted: Mon Feb 26, 2007 08:20 PM
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

Continue the discussion