本文介绍了单击时如何使复选框更改其状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经使用以下代码在WinAPI中创建了一个复选框:

I have created a checkbox in WinAPI using the following code:

HWND checkbox = CreateWindowEx(NULL, "BUTTON", "Click Me!", WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 10, 10, 60, 20, hWnd, NULL, hInstance, NULL);

我希望该复选框在单击时会自动更改其状态,但是并没有!

I expected the checkbox to change its state automatically when clicked, however it did not!

我没有在MSDN上找到任何示例,那么如何单击该复选框以更改其状态?我应该处理 WM_COMMAND 消息并查看它处于什么状态,然后将其状态更改为相反的状态?

I did not find any example on MSDN, so how can I make the checkbox change its state when clicked? should I handle the WM_COMMAND message and see what state it is in, and then change its state to the opposite one?

推荐答案

使用 BS_AUTOCHECKBOX 样式代替 BS_CHECKBOX .

按钮样式

按钮状态

按钮的状态可以通过其焦点状态,按下状态和检查状态来表征.

A button's state can be characterized by its focus state, push state, and check state.

...

检查状态
...
系统会自动更改自动按钮的检查状态,但是应用程序必须更改非自动按钮的检查状态.

Check State
...
The system automatically changes the check state of an automatic button, but the application must change the check state of a non-automatic button.

更改为按钮状态

当用户选择一个按钮时,通常需要更改一个或多个按钮的状态元素.系统自动更改...所有自动按钮的检查状态.应用程序必须考虑按钮的类型,样式和当前状态,进行所有其他状态更改.

When the user selects a button, it is generally necessary to change one or more of the button's state elements. The system automatically changes ... the check state for all automatic buttons. The application must make all other state changes, taking into account the button's type, style, and current state.

这篇关于单击时如何使复选框更改其状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:57