4

我使用 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 的空白区域或单击任何项​​目时。但我只想在复选框更改时运行消息框。

4

1 回答 1

3
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;
   }
}
于 2013-04-03T12:24:50.260 回答