gpt4 book ai didi

c++ - winapi listview检查项c++

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:44 24 4
gpt4 key购买 nike

我使用 minGW32 编译器。我创建了一个带有复选框的 ListView,如下所示:

HWND hListView = CreateWindowExW(0, WC_LISTVIEWW, L"",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_EDITLABELS,
10,10,500,500, hwnd, (HMENU)ID_LISTVIEW, GetModuleHandle(NULL), NULL);
SendMessage(hListView, WM_SETFONT, (WPARAM) font, TRUE);

ListView_SetExtendedListViewStyle(hListView, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_GRIDLINES/*LVSCW_AUTOSIZE_USEHEADER*/);

lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;

而且我想检查是否选中了任何复选框。例如。如果我选中任何复选框,则显示一个消息框:

I use this WM_NOTIFY:
case WM_NOTIFY:
{
switch (LOWORD(wParam))
{
case ID_LISTVIEW:
{
switch (((LPNMHDR) lParam)->code)
{
case LVN_ITEMCHANGED :
MessageBoxW( NULL, (LPCWSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONERROR );
}
break;
}
break;
}
break;
}
break;

但这总是发生。当我单击 ListView 的空白区域或单击任何项​​目时。但我只想在更改复选框时运行消息框。

最佳答案

LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; 

if(pnmv->uChanged & LVIF_STATE) // item state has been changed
{
switch(pnmv->uNewState & LVIS_STATEIMAGEMASK)
{
case INDEXTOSTATEIMAGEMASK(2):
// pnmv->iItem was checked
break;
case INDEXTOSTATEIMAGEMASK(1):
//pnmv->iItem was unchecked
break;
}
}

关于c++ - winapi listview检查项c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com