按下返回键时MFC应用程序关闭,而焦点位于工具栏按钮上 [英] MFC Application gets closed when Return Key is pressed while focus is on Toolbar button

查看:87
本文介绍了按下返回键时MFC应用程序关闭,而焦点位于工具栏按钮上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是MFC的新手。



我在MFC中创建了一个Dialog应用程序。

我在对话框中添加了两个按钮,并且动态地创建了一个工具栏并在工具栏中添加了两个按钮。



NOw,ON选项卡更改,我将焦点放在工具栏的按钮上但是当按下回车键时,应用程序将关闭。

我实现了一个重写的函数PreTranslateMessage。但是在按下Enter键时,不会调用此重写的函数。 ON输入Key Down,调用Oncancel事件并关闭应用程序。



但是当我创建一个简单的按钮,并在按下回车键时,被调用的函数PreTranslateMessage被调用正确。



任何人都可以帮我找到一个好的解决方案吗?

我会非常感激并提前感谢你。 />


问候,

Lakshmanan CB

Hello,

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.

Regards,
Lakshmanan C B

推荐答案

可能是因为你的OK按钮是默认情况下,按Enter键将被触发。尝试阅读 http:// msdn。的对话框的使用和编程。 microsoft.com/en-us/library/ms632588(v=vs.85).aspx [ ^ ]。
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 http://msdn.microsoft.com/en-us/library/ms632588(v=vs.85).aspx[^].


覆盖CDialog :: OnOk(){}(什么都不做) 。



为了避免取消,重写CDialog :: OnCancel(){}(什么也不做)



希望它有所帮助。
Override CDialog::OnOk(){} (do nothing).

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

Hope it helps.


这篇关于按下返回键时MFC应用程序关闭,而焦点位于工具栏按钮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆