On Init SetFocus Issue

On Init SetFocus Issue

Postby nageswaragunupudi » Sat Nov 03, 2007 1:01 pm

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  Expand view  RUN
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
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Antonio Linares » Sat Nov 03, 2007 1:05 pm

Code: Select all  Expand view  RUN
   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT ( oBrw:SetFocus(), .F. )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: On Init SetFocus Issue

Postby Richard Chidiak » Sat Nov 03, 2007 1:23 pm

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
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby nageswaragunupudi » Sat Nov 03, 2007 2:23 pm

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
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Antonio Linares » Sat Nov 03, 2007 5:25 pm

>
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
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby nageswaragunupudi » Sat Nov 03, 2007 5:36 pm

Mr Antonio

Thanks for the clarification. Quite educative.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests