FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Pushbutton Default FWH 1201
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 02:22 PM
To All

Using the DEFAULT clause on creating a button from code does not seem to work .. Default is on the Cancel button, not on OK ..

Rick Lipkin

Consider this code:

Code (fw): Select all Collapse
#Include "FiveWin.ch"

Static cSAY,oSay

//---------------
Func Main()

LOCAL oBtn1,oBtn2,oDlg

cSay := Space(30)


DEFINE DIALOG oDlg                          ;
       FROM 10, 2 to 30, 55                 ;
       TITLE "DEFAULT Button Test"           ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

   @ 3,3 Say oSay var cSay of oDlg

   @ 6,16 BUTTON oBtn1 Prompt "&Ok"         ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( nil )

   @ 6,23 BUTTON oBtn2 Prompt "&Cancel"     ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( oDlg:END() ) DEFAULT

ACTIVATE DIALOG oDlg


Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 04:09 PM

Rick,

try setting the 'DEFAULT' clause to the Ok-Button :wink:

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 06:31 PM

Frank

Strange error .. if you leave the dialog without any controls .. the above behavior is what you will get .. If you add a Get or a radio button the DEFAULT clause on the Cancel button works just fine.

Rick

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 07:13 PM

Rick,

In your example you don't have an action for the OK button. It is nil.

Try it with this change:

@ 6,16 BUTTON oBtn1 Prompt "&Ok" ;
SIZE 30,25 of oDLG ;
ACTION MsgBeep()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 07:19 PM

Antonio

No change on the default button by adding msgbeep() .. :( .. I noticed this as I was building the IE Page Scrape example for the forum .. Strangely.. when I added a control, the Cancel button showed up as Default.

Rick

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 07:24 PM

Rick,

Please notice that such beahvior is controled fom METHOD KeyChar( nKey, nFlags ) CLASS TControl so until there is no a control on the dialog it may not get properly precessed.

If Class TButton uses a different Method KeyChar() that may explain the difference.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 07:33 PM

Antonio

Thank you for your help !! I doubt if an empty dialog would ever occur... no need to spend any of your time on this..

I always create my forms from .rc and was trying to create a form from code .. As I was lining up the buttons I noticed the behavior .. as I started putting gets, says and radio buttons in the mix .. The Default worked.

Again, Many Thanks

Rick

Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Pushbutton Default FWH 1201
Posted: Sat Feb 04, 2012 08:06 PM
Rick, Antonio,

it's (only) standard default behavior, if the focus is on a Button, the Button action will be triggered on VK_RETURN , NOT the Standard-Pushbutton!

So, everything is all right :-)

See also sample:
Code (fw): Select all Collapse
Func Main()

   LOCAL oBtn1,oBtn2,oDlg

   cSay := Space(30)


   DEFINE DIALOG oDlg                          ;
       FROM 10, 2 to 30, 55                 ;
       TITLE "DEFAULT Button Test"           ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

   @ 3,3 Say oSay var cSay of oDlg

   @ 6,16 BUTTON oBtn1 Prompt "&Ok";
      SIZE 30,25;
      OF oDLG;
      ACTION( OkButton() )

   @ 6,23 BUTTON oBtn2 Prompt "&Cancel"     ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( oDlg:END() )  DEFAULT

   ACTIVATE DIALOG oDlg
RETURN NIL

FUNCTION OkButton()
    MsgInfo( "Here is the Ok Button!" )
RETURN NIL
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86

Continue the discussion