On Init SetFocus Issue

Post Reply
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

On Init SetFocus Issue

Post by nageswaragunupudi »

When I have button and wbrowse controls in a dialog, I can not start with the browse focussed even when i use on init browse:setfocus. Here is an example.

Code: Select all

FUNCTION BrwFocusTest

   LOCAL oDlg, oBrw, oBtn

   USE CUSTOMER NEW ALIAS CUST

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL

   @ 10,10 BUTTON oBtn PROMPT 'Button' SIZE 40,12 PIXEL OF oDlg

   @ 30,10 LISTBOX oBrw FIELDS ;
         SIZE 80, 60 PIXEL OF oDlg ;
         ALIAS 'CUST'


   oBrw:nClrBackFocus   := CLR_GREEN
   oBrw:nClrForeFocus   := CLR_WHITE

   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT oBrw:SetFocus()

RETURN NIL
I want the browse to get focus when the dialog starts. Despite the ON INIT clause, the focus is on the button.

There are two workarounds though. But I think this should work without workarounds. Can someone help me how to set focus to the browse initially ?

I adopt one of the following two workarounds, but they are workarounds. I guess it should work without any workarounds:

1. After defining the button, oBtn:nStyle -= WS_TABSTOP. Then naturally oBrw is the first control with tabstop and so it gets the focus anyway.

2. Define the browse first and define the button in the subsequent program code. That way browse gets 1st tab stop and button gets the second tabstop despite their appearance.

But I want to focus on the browse initially without disturbing the taborders of the controls. How can I do this please?
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Code: Select all

   ACTIVATE DIALOG oDlg CENTER ; 
      ON INIT ( oBrw:SetFocus(), .F. ) 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

Re: On Init SetFocus Issue

Post by Richard Chidiak »

An easy way that always works for me

ODLG:bSTART := { || OBRW:SETFOCUS() }

Hth

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Mr Antonio and Mr Richard

Thank you both very much. Yes both solutions work.

But Mr Antonio, will you kindly enlighten me what magic does this .F. return value do ? Why is it important?
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

>
But Mr Antonio, will you kindly enlighten me what magic does this .F. return value do ? Why is it important?
>

It is the way the Windows API has been designed. FWH uses the standard Windows dialogbox procedure. From the Microsoft API docs:

>
The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus.
>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Mr Antonio

Thanks for the clarification. Quite educative.
Regards

G. N. Rao.
Hyderabad, India
Post Reply