0
votes

I have a tab control with some dialogs as tab pages, I have a button in each of them that creates the next tab, those buttons are set as default buttons, so when I press enter key it goes to next tab. but, after you press those buttons, they become disabled, and when you go back to that tab it doesn't allow the client to click on next button again, the problem is that when I press enter when the buttons are disabled and are not default buttons any more, the tab pages get closed! It seems enter closes the dialogs! but when I change the tab and come back to that tab again, dialog is showed again!So it means enter does not destroy or close that dialog!

Dialog when the button is enabled.Pressing enter is like clicking on the button: enter image description here Same dialog after it creates the next tab: enter image description here Pressing enter when the next step button is disabled! enter image description here The Dialog after changing the tabs and comming back to that tab again! enter image description here

I don't understand it's behavior! Notice that I didn't wrote anything for enter button, I just set those buttons as default button, and even when those buttons are not default buttons, it happens!what should I do?

1
Hard to guess, a screenshot is a poor substitute for a code snippet. But the default button of a dialog is like the OK button. It closes the dialog.Hans Passant

1 Answers

1
votes

The default action for dialogs (i.e. what gets called when you press enter, if the focus is not in another button or control that captures enter) is to call OnOk, and by default, OnOk closes the dialog.
So you have to override the dialogs' OnOK function and give them an empty body:

void CMyTabDlg::OnOk()
{
    // Nothing, so it does not close the dialog
}

Also, you can set the default button to some other button, but I would do the override OnOk thing anyway, just to be safe.