当两个按钮映射时 CDialog 未关闭

发布于 2024-07-11 07:00:01 字数 531 浏览 6 评论 0原文

Visual Studio 2005、C++、Windows XP。

我有一个带有单个按钮的 CDialog,它调用如下函数:

BEGIN_MESSAGE_MAP(Foo, BaseDlg) //BaseDlg inherits from CDialog
    ON_BN_CLICKED(IDBAR, Bar)
END_MESSAGE_MAP()

单击“X”时对话框将关闭。

我将上面的代码更改为:

BEGIN_MESSAGE_MAP(Foo, BaseDlg) //BaseDlg inherits from CDialog
    ON_BN_CLICKED(IDBAR, Bar)
    ON_BN_CLICKED(IDBAZ, Baz)
END_MESSAGE_MAP()

我的对话框窗口将不再关闭。 每当单击 X 时,就会调用 Baz()。 由于某种原因,第二个 ON_BN_CLICKED() 处理程序正在替换正常的对话框关闭行为。

如何关闭具有两个或多个映射到功能的按钮的对话框?

Visual Studio 2005, C++, Windows XP.

I have a CDialog with a single button, which calls a function like so:

BEGIN_MESSAGE_MAP(Foo, BaseDlg) //BaseDlg inherits from CDialog
    ON_BN_CLICKED(IDBAR, Bar)
END_MESSAGE_MAP()

The dialog box closes when its 'X' is clicked.

I change the above code to:

BEGIN_MESSAGE_MAP(Foo, BaseDlg) //BaseDlg inherits from CDialog
    ON_BN_CLICKED(IDBAR, Bar)
    ON_BN_CLICKED(IDBAZ, Baz)
END_MESSAGE_MAP()

My dialog window will no longer close. Whenever the X is clicked, Baz() is called. The second ON_BN_CLICKED() handler is replacing the normal dialog close behavior for some reason.

How do I close a dialog box which has two or more buttons mapped to functions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肤浅与狂妄 2024-07-18 07:00:01

资源文件中分配给 IDBAR 和 IDBAZ 的数值是什么? 一种可能的解释是 IDBAZ == IDCANCEL,它在 MFC 中默认定义为对话框的取消按钮和 X 按钮的 ID。 为该常量定义您自己的处理程序将覆盖默认行为,即关闭窗口。 这仅适用于您以模态方式显示对话框的情况 - 如果它是无模式的,那么您始终必须通过调用 EndDialog() 自行关闭对话框。

What are the numeric values assigned to IDBAR and IDBAZ in the resource file? One possible explanation is that IDBAZ == IDCANCEL, which is defined in MFC by default as the ID for both the dialog's cancel and X buttons. Defining your own handler for this constant will then override the default behaviour, which is to close the window. This only applies though if you're showing the dialog modally - if it's modeless then you always have to close the dialog yourself by calling EndDialog().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文