c ++ winapi listview项目select,但没有突出显示

这里是我的对话框的dialogProc包含listview对话框是由我的应用程序的主窗口中的一个简单的button创build的。 问题是ListView_SetItemState成功,但项目没有突出显示。 另外当我手动点击一个项目(图标)只有图标被选中(突出显示),而不是项目的整个RECT。 谢谢你的帮助。

BOOL CALLBACK DialogProc(HWND ihDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { TCHAR pszfile[MAX_PATH]; SIZE size; int selected_icon,wn_v; char buffer[MAX_PATH]; LVTILEVIEWINFO tileViewInfo; LVCOLUMN LvCol; size_t i; switch(uMsg) { case WM_INITDIALOG: EnableWindow(GetParent(ihDlg),false); hDLGedit = CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_HSCROLL|ES_AUTOHSCROLL| WS_CHILD|WS_VISIBLE,5,25,250,25,ihDlg,(HMENU) DLG_edit_BX,0,0); hDLGb_browse = CreateWindowEx(WS_EX_CLIENTEDGE,L"BUTTON",L"Browse", WS_CHILD|WS_VISIBLE,257,25,60,25,ihDlg,(HMENU) DLG_bt_BROWS,0,0); hDLGlistv = CreateWindow(WC_LISTVIEW,L"",WS_HSCROLL|LVS_AUTOARRANGE|LVS_ICON|LVS_SINGLESEL| WS_VISIBLE|WS_CHILD | LVS_REPORT | LVS_EDITLABELS,10,80,425,150,ihDlg,(HMENU) DLG_LIST_icons,0,0); size.cx=45; size.cy=45; tileViewInfo.cbSize = sizeof(tileViewInfo); tileViewInfo.dwFlags = LVTVIF_FIXEDSIZE; tileViewInfo.dwMask = LVTVIM_COLUMNS | LVTVIM_TILESIZE; tileViewInfo.cLines = 2; tileViewInfo.sizeTile = size; ListView_SetTileViewInfo(hDLGlistv, &tileViewInfo); LvCol.mask=LVCF_IMAGE; LvCol.fmt=LVCFMT_IMAGE; LvCol.pszText=L"Item"; ListView_InsertColumn(hDLGlistv,0,&LvCol); ShowScrollBar(hDLGedit,SB_HORZ,0); GetWindowsDirectory(pszfile,MAX_PATH); wcscat_s(pszfile,50,TEXT("\\system32\\SHELL32.dll")); SendMessage(hDLGedit,WM_SETTEXT,0,reinterpret_cast<LPARAM>(pszfile) ); iload_Icons(hDLGlistv,pszfile);//just a function that loads icons and fill up the listview ListView_SetView(hDLGlistv,LV_VIEW_TILE); ListView_SetItemState(hDLGlistv,0,LVIS_FOCUSED | LVIS_SELECTED,LVIS_FOCUSED | LVIS_SELECTED); break; case WM_PAINT: // some painting break; case WM_COMMAND: switch(LOWORD(wParam)) { case DLG_edit_BX: return TRUE; case DLG_bt_BROWS: Do_icon_open(ihDlg);// just filling the listview ListView_SetItemState(hDLGlistv,0,LVIS_FOCUSED | LVIS_SELECTED,LVIS_FOCUSED | LVIS_SELECTED ); return TRUE; case IDOK: SendMessage(hDLGedit, WM_GETTEXT, 260, (LPARAM) pszfile); selected_icon= ListView_GetNextItem(hDLGlistv, -1, LVNI_SELECTED); // some code related to the selection of an icon EndDialog(ihDlg, wParam); hDlg=NULL; break; case IDCANCEL: EndDialog(ihDlg, wParam); hDlg=NULL; //golobal varialble (the dialog itself break; } case WM_CLOSE: EndDialog(ihDlg, wParam); hDlg=NULL; break; case WM_DESTROY: PostQuitMessage(0); break; } return 0; 

}

即使LVS_SHOWSELALWAYS没有焦点, LVS_SHOWSELALWAYS使用LVS_SHOWSELALWAYS窗口样式。

如果您希望在选中时突出显示项目AND子项目,请使用LVS_EX_FULLROWSELECT窗口扩展样式。

使用CreateWindowExSetWindowLongGWL_EXSTYLE ,可以指定扩展样式。