c ++ winapi listview项目已选中但未突出显示

时间:2013-12-22 11:59:18

标签: c++ windows winapi listview

这是包含listview的对话框的dialogProc 该对话框由我的应用程序主窗口中的一个简单按钮创建。 问题是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;

}

1 个答案:

答案 0 :(得分:1)

如果您希望显示选择,即使列表视图没有焦点,也可以使用LVS_SHOWSELALWAYS窗口样式。

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

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