FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour On Init SetFocus Issue
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

On Init SetFocus Issue

Posted: Sat Nov 03, 2007 01: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.

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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

On Init SetFocus Issue

Posted: Sat Nov 03, 2007 01:05 PM
   ACTIVATE DIALOG oDlg CENTER ; 
      ON INIT ( oBrw:SetFocus(), .F. )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM

Re: On Init SetFocus Issue

Posted: Sat Nov 03, 2007 01: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

On Init SetFocus Issue

Posted: Sat Nov 03, 2007 02: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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

On Init SetFocus Issue

Posted: Sat Nov 03, 2007 05: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

On Init SetFocus Issue

Posted: Sat Nov 03, 2007 05:36 PM

Mr Antonio

Thanks for the clarification. Quite educative.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion