here is the dialogProc for my dialog box that contains the listview the dialog is created by a simple button from the main window of my application . the problem is ListView_SetItemState succeeds but the item is not highlighted . also when i manually click an item (icon) only the icon is selected (highlighted) not the entire RECT of the item. thanks for your help.
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;
}
Use the LVS_SHOWSELALWAYS
window style if you want the selection to be shown even if the Listview does not have the focus.
Use the LVS_EX_FULLROWSELECT
window extended style if you want item AND sub-item highlighted when selected.
Use CreateWindowEx
, or SetWindowLong
with GWL_EXSTYLE
, to be abble to specify the extended style.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.