Setting the focus to any object

Setting the focus to any object

Postby Maurilio Viana » 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):

Code: Select all  Expand view
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  Expand view
function xFocus(oObj)
xSetFocus(oObj)
xSetFocus(oObj)
return Nil


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

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

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


Return to Utilities / Utilidades

Who is online

Users browsing this forum: No registered users and 4 guests