CListView CImageList parameters in question ?

Category: VC/MFC -> Foundation Classes Author: zhangyan19820808 Date: 2013-11-03 19:03:13
 
zhangyan19820808
2013-11-03 19:03:13
With clistview implements a file browser , like windows explorer , just not to the left of the tree. Use the following code to obtain a variety of file icons :
HICON   CGetFileIcoDlg :: GetFilesIcon (CString   FilesName)
{
// first processing exe file
HICON   hIcon = ::   ExtractIcon (AfxGetInstanceHandle (),
_T (FilesName), 0);
if   (hIcon   & &! hIcon = (HICON) -1)
return   hIcon;

// handle various types of extensions
SHFILEINFO   shfi;
memset (& shfi, 0, sizeof (shfi));
:: SHGetFileInfo (FilesName,
FILE_ATTRIBUTE_NORMAL,
& shfi,
sizeof (shfi),
SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
return   shfi.hIcon;
} so after

, how to make these icons are displayed in the listview inside , CListView of insertcolumn () seems to need a CImageList parameters.
Thank you
yuino
2013-11-03 19:18:21
// in OnInitialUpdate message view, first set up an listview associated imagelist
GetListCtrl () SetExtendedStyle. (LVS_EX_FULLROWSELECT  );
m_pImageList   =   new   CImageList (); // normal icon
m_pImageListSmall   =   new   CImageList (); // small icon
ASSERT (m_pImageList  ! =   NULL   & &   m_pImageListSmall  ! =   NULL);         //   serious   allocation   failure   checking
CTDCApp   * pApp   =   (CTDCApp   *) AfxGetApp (); @ obtain application
m_pImageList- > Create (32,   32,   TRUE,     4,   4);
m_pImageListSmall- > Create (16,   16,   TRUE,   4,   4);
m_pImageList- > Add (pApp- > LoadIcon (IDI_ICON_CHECKIN)); // 1.CHECKIN
m_pImageListSmall- > Add ( pApp- > LoadIcon (IDI_ICON_CHECKIN));
m_pImageList- > Add (pApp- > LoadIcon (IDI_ICON_CHECKOUT)); // 2.CHECKOUT
m_pImageListSmall- > Add (pApp- > LoadIcon (IDI_ICON_CHECKOUT));
m_pImageList- > Add (pApp- > LoadIcon (IDI_ICON_OLD_VERSION)); // 3.OLDVERSION
m_pImageListSmall- > Add (pApp- > LoadIcon (IDI_ICON_OLD_VERSION));
GetListCtrl () SetImageList (m_pImageList,   LVSIL_NORMAL);. // icon bound to listctrl
GetListCtrl () SetImageList (m_pImageListSmall,   LVSIL_SMALL);.

@ insert icon
int                           iActItem;
LV_ITEM                   lvitem;
LPWSTR   strGUID;
// right GUID for processing, is converted to a string
StringFromCLSID (DocGUID, & strGUID);
lvitem.mask   =   LVIF_TEXT   |   LVIF_IMAGE  ; // pledged to add icons
lvitem.iImage   =   0; // refers icon
lvitem IMAGELIST first position . iItem = GetListCtrl () GetItemCount ();.
lvitem.iSubItem   = 0;
lvitem.pszText = pItemName;.
iActItem = GetListCtrl () InsertItem (& lvitem);   //   insert   new   item