关闭(X)按钮在对话框中不起作用? [英] Close(X) button is not working in the dialog?

查看:111
本文介绍了关闭(X)按钮在对话框中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关闭(X)按钮在对话框中不起作用?当按下对话框中的X按钮时,它没有关闭对话框,并且在对话框中添加了命令按钮,添加了取消代码,对话框仍未关闭。

Close(X) button is not working in the dialog? When pressing the X button in the dialog, it is not closing the dialog and also added command button in the dialog, added codes for cancel, still the dialog is not getting closed.

推荐答案

你有WM_CLOSE的处理程序吗?如果你不调用CDialog :: OnClose(),这将阻止它关闭。
Do you have a handler for WM_CLOSE? If you don''t call CDialog::OnClose() this will prevent it from closing.


你好。

你不需要处理WM_CLOSE ,

你是否超载了OnCancel()功能?

如果没有,你必须重载OnCancel()函数并添加此代码



CDialog :: OnCancel();



你可以吼叫。

首先你创建名为IDCANCEL的按钮。

和IDCANCEL,定义OnCancel()函数。
Hello.
You don''t need to handle WM_CLOSE,
Did you overload a OnCancel()fuction?
If there isn''t, you have to overload OnCancel() function and add this code

CDialog::OnCancel();

You can do as bellow.
First you create button named IDCANCEL.
and from IDCANCEL, define OnCancel()function.


上面提到的解决方案是你的问题的答案,我只是添加它。 。



每当你开始使用基于MFC Dialog的应用程序时。

你会看到一个对话框,其中有两个按钮OK&CANCEL。

执行程序时单击其中任何一个将退出应用程序。

很多时候我们不需要它们所以我们删除它们然后问题就是你的应用程序即使单击ENTER或E也会退出键盘上的SC键。



所以你可以执行以下操作

1.双击OK&CANCEL按钮,你将有两个为ID_OK和ID_CANCEL创建的函数(假设是OK和CANCEL按钮的ID)。

2.在为ID_OK创建的函数中注释OnOK()将阻止您的应用程序在ENTER键出现时退出在应用程序运行时命中。

3.在为ID_CANCEL创建的函数中,您可以调用一个消息框,询问用户是否退出应用程序并相应地根据输入操作。
Above mentioned solutions are answers to your question, i am just adding to it..

Whenever you start with a MFC Dialog based application.
You are given a dialog with two buttons OK & CANCEL.
Clicking either of them when your program is executed will exit the application.
Many times we don''t need them & so we delete them, then the problem would be that your application will exit even on clicking a ENTER or ESC key from keyboard.

So you can do the following
1. Double click both the OK & CANCEL button, you will have two function created for ID_OK & ID_CANCEL (assumed to be Ids of your OK & CANCEL button).
2. Commenting OnOK() in the function created for ID_OK will prevent your application from exiting when an ENTER key is hit when your application is running.
3. In the function created for ID_CANCEL you can call a message box asking user whether to exit the application or not & based on the input act accordingly.


这篇关于关闭(X)按钮在对话框中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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