Pushbutton Default FWH 1201

Pushbutton Default FWH 1201

Postby Rick Lipkin » Sat Feb 04, 2012 2: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: Select all  Expand view


#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

 


Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Pushbutton Default FWH 1201

Postby frose » Sat Feb 04, 2012 4: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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Pushbutton Default FWH 1201

Postby Rick Lipkin » Sat Feb 04, 2012 6: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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Pushbutton Default FWH 1201

Postby Antonio Linares » Sat Feb 04, 2012 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42086
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Pushbutton Default FWH 1201

Postby Rick Lipkin » Sat Feb 04, 2012 7: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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Pushbutton Default FWH 1201

Postby Antonio Linares » Sat Feb 04, 2012 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42086
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Pushbutton Default FWH 1201

Postby Rick Lipkin » Sat Feb 04, 2012 7: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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Pushbutton Default FWH 1201

Postby frose » Sat Feb 04, 2012 8: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: Select all  Expand view
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests