Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am new to MFC.

I have created a Dialog in MFC application.
I have added two buttons in the dialog and
dynamically i have created a Toolbar and added two buttons to the Toolbar.

NOw, ON tab change, I am getting the focus in the button of tool bar but when enter key is pressed the application gets closed.
I have implemented a overridden function PreTranslateMessage. But on Enter key pressed, this overridden function is not called. ON Enter Key Down, Oncancel event is called and application gets closed.

But when i created a simple button, and on enter key press, the overridden Function PreTranslateMessage is called properly.

Can any one help me on finding a good solution?
I will be really grateful and thanking you in advance.

Lakshmanan C B

Probably because your OK button is the default, and will get fired when you press enter. Try reading up on the use and programming of dialogs at[^].
Share this answer
Override CDialog::OnOk(){} (do nothing).

To avoid cancel, override CDialog::OnCancel(){} (do nothing)

Hope it helps.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900