Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#18 Default Push Button doesn't work (BS_DEFPUSHBUTTON)

open
nobody
None
5
2007-03-15
2007-03-15
Conrado PLG
No

If there is a button with the BS_DEFPUSHBUTTON style in a dialog, it isn't "pressed" when you hit Enter.

Also, when you press Esc, the dialog isn't closed.

Discussion

  • Conrado PLG
    Conrado PLG
    2007-03-17

    Logged In: YES
    user_id=1103883
    Originator: YES

    Sorry for not being more specific, I tested only the pure modal dialog in the WidgetDialog example. It doesn't work there, but it works on the resource modal dialog.

    So the problem is only with pure modal dialogs...

     
  • Conrado PLG
    Conrado PLG
    2007-03-18

    Logged In: YES
    user_id=1103883
    Originator: YES

    OK, I think I know the reason...
    In MessageMap.h, on sendWidgetMessage, the WM_COMMAND msg is routed to children.
    In mainWndRouteChild, the msg is wrongly assumed to be from a menu.

    So,
    if ( ( msg == WM_COMMAND && lPar == 0 && HIWORD( wPar ) == 0 ) || etc.
    should be actually,
    if ( ( msg == WM_COMMAND && lPar == 0 && HIWORD( wPar ) == 0 && LOWORD(wPar) != IDCANCEL && LOWORD(wPar) != IDOK ) || etc.

    BUT, probably it shouldn't be routed to children at all... So, I don't know what is the "right" way to fix this. My guess is to change sendWidgetMessage for these special cases of WM_COMMAND and invoke the default button onClick event or end the dialog accordingly.

    And I have no idea why it works on resource based dialogs...

     
  • andrew7
    andrew7
    2007-03-18

    Logged In: YES
    user_id=1157678
    Originator: NO

    I have a fix.

    In WidgetButton's Seed class, add the following function:
    void setControlId( int id ) {
    menuHandle= id;
    }

    Then before you create a button, use a seed, and call the above function with either IDCANCEL or IDOK.
    WidgetButton::Seed cancelSeed; cancelSeed.setControlId( IDCANCEL );
    itsCancelButton = createButton( cancelSeed );
    ...
    WidgetButton::Seed okSeed; okSeed.setControlId( IDOK );
    itsOkButton = createButton( okSeed );
    (I did this in WidgetModalDialog's NumDialog.h, and it gave me the Esc and Enter behaviour.)

    The reasoning is from MSDN

    "To permit the user to close the dialog box, the template should specify at least one push button and give it the control identifier IDCANCEL. To permit the user to choose between completing or canceling the task associated with the dialog box, the template should specify two push buttons, labeled OK and Cancel, with control identifiers of IDOK and IDCANCEL, respectively."
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/aboutdialogboxes.asp

    And since SmartWin++ did not have a way for Pure dialogs to specify the control identifier, then the pure dialog lacked the Esc and Enter functionality. The resource based dialog specifies the control id, and thus had the functionality.

     
  • Conrado PLG
    Conrado PLG
    2007-03-18

    Logged In: YES
    user_id=1103883
    Originator: YES

    Works for me.... I missed that entirely. Now I get it. Thank you very much!

     
  • Tobbe
    Tobbe
    2007-03-18

    Logged In: YES
    user_id=1221788
    Originator: NO

    Is this something that's going to be added to cvs, or should we do it ourselves?