901224-为对话框的按钮使用ON_UPDATE_COMMAND_UI [英] 901224 - using ON_UPDATE_COMMAND_UI for buttons of a dialog

查看:262
本文介绍了901224-为对话框的按钮使用ON_UPDATE_COMMAND_UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 而不是处理BN_CLICKED,我使用ON_COMMAND处理对话框中的按钮,以使处理程序被调用,不仅可以通过单击按钮,还可以在按钮聚焦时按Enter键或空格键.

1)我说的对吗?换句话说,如果我在按Enter或空格时处理BN_CLICKED而不是WM_COMMAND,则不会调用处理程序吗?

然后我添加了ON_UPDATE_COMMAND_UI来使按钮在特定条件下被禁用.但即使条件为假,也会调用处理程序.

2)为什么?

解决方案

我将使用BN_CLICKED来具有标准行为.使用其他方法可能会使用户感到困惑.

Update UI机制仅适用于框架窗口派生的类,因为在诸如CDialog的其他类中找不到调用UI处理程序的代码.
要禁用拨号中的按钮,请使用按钮窗口的EnableWindow().但是,您不能禁用具有焦点的按钮.如果要禁用此类按钮,则必须使用GotoDlgCtrl()将焦点移至另一个控件.


hi instead of handling BN_CLICKED, i used ON_COMMAND for handling a button in a dialog box for the handler to be called not only by clicking on the button but also by hitting enter key or space key when the button is focused.

1) am i right? in another words, isn''t handler called if i handle BN_CLICKED instead of WM_COMMAND when i hit enter or space?

then i added ON_UPDATE_COMMAND_UI for the button to get disabled in a specific condition. but even when the condition is false the handler is called.

2) why?

解决方案

I would use BN_CLICKED to have the standard behaviour. Using other methods may confuse the users.

The Update UI mechanism does only work with frame window derived classes because the code that calls the UI handlers is not found in other classes like CDialog.

To disable a button in a dialag, use EnableWindow() of the button window. But you must not disable a button that has the focus. If you want to disable such a button, you must move the focus to another control using GotoDlgCtrl().


这篇关于901224-为对话框的按钮使用ON_UPDATE_COMMAND_UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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