处理CListCtrl鼠标点击的问题

发布于 2024-10-09 16:52:24 字数 125 浏览 0 评论 0原文

我有一个带有复选框的 listctrl(LVS_EX_CHECKBOXES)。它是一个单列列表控件。我的问题是,当我单击复选框时,特定项目被选中/取消选中。但是,当我单击项目文本时,相应的复选框没有被选中/取消选中。如何处理这两种情况。

I have a listctrl with CheckBox in it(LVS_EX_CHECKBOXES) .It is a single column List Control . My Problem is when I Click on the CheckBox the particular item is getting selected/UnSelected. But when I click on the Item text the corresponding Checkbox is not getting Selected/UnSelected . How to handle both the Scenarios.

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

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

发布评论

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

评论(1

终难愈 2024-10-16 16:52:25

要在用户单击项目文本时检查该项目,您必须处理 NM_CLICK 消息,每当用户单击该项目时都会发送该消息。

大致如下:

CYourListCtrl::OnNMClick(NMHDR* pNMHDR, LRESULT* pResult)
{

LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);

int nItemIndex = pNMItemActivate->iItem;

BOOL bCurrentCheckState = GetCheck(nItemIndex);

SetCheck(nItemIndex, !bCurrentCheckState);

*pResult = 0;

}

我在编写此内容时没有进行测试,因此您必须确保它不会与单击复选框本身的处理程序发生冲突。

To check the item when the user clicks on the item text, you'll have to handle the NM_CLICK message, which is sent whenever the user clicks on the item.

Something along the lines of:

CYourListCtrl::OnNMClick(NMHDR* pNMHDR, LRESULT* pResult)
{

LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);

int nItemIndex = pNMItemActivate->iItem;

BOOL bCurrentCheckState = GetCheck(nItemIndex);

SetCheck(nItemIndex, !bCurrentCheckState);

*pResult = 0;

}

I'm writing this without testing though, so you'll have to make sure that it doesn't conflict with the handler for clicks on the check box iteself.

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