Yes, you can set the default button in the dialog editor. Select the button and then choose properties, and set
Default
in the
Behaviour
group as
true
. Remember to set the
OK
button's
Default
setting to
false
. You may also need to adjust the tab order.
[edit]
It seems that the order of the buttons in the dialog is also necessary for this to work. in the following
Dialog
, pressing the
Enter
key invokes the
Cancel
button:
IDD_DIALOG1 DIALOGEX 0, 0, 310, 177
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Cancel",IDCANCEL,253,156,50,14
PUSHBUTTON "OK", IDOK, 199, 156, 50, 14
END
However, in the following layout when the order is reversed it still invokes the
OK
button, even though it is not the default:
IDD_DIALOG1 DIALOGEX 0, 0, 310, 177
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "OK", IDOK, 199, 156, 50, 14
DEFPUSHBUTTON "Cancel",IDCANCEL,253,156,50,14
END
[/edit]