```
## 常用代码
```c++ m_wndList.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS, CRect(0, 0, 0, 0), this, IDC_FRM_FILE_LIST); m_wndList.SetExtendedStyle(m_wndList.GetExtendedStyle() | LVS_EX_DOUBLEBUFFER | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
m_wndList.InsertColumn(0, TEXT("Name"), LVCFMT_LEFT, 400); m_wndList.InsertColumn(1, TEXT("Ext"), LVCFMT_LEFT, 130); m_wndList.InsertColumn(2, TEXT("Size"), LVCFMT_LEFT, 80); m_wndList.InsertColumn(3, TEXT("Date"), LVCFMT_LEFT, 100);
m_wndList.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); if (m_wndList.GetColumnWidth(0) < 200) { m_wndList.SetColumnWidth(0, 200); } m_imageList.Create(16, 16, ILC_COLOR24, 7, 7); m_wndList.SetImageList(&m_imageList, LVSIL_SMALL);
BOOL CDlgIconList::FillList(HWND hwnd) {
CDevHelperApp* pwnd = (CDevHelperApp*)AfxGetApp(); ListView_SetImageList(hwnd, pwnd->m_hLarge, LVSIL_NORMAL);
count = ImageList_GetImageCount(pwnd->m_hLarge);
LVITEM lvitem; TCHAR ach[20]; for (int i = 0; i < 10; ++i) { wsprintf(ach, TEXT("%d"), i); lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.pszText = ach; ListView_InsertItem(m_wndView.m_hWnd, &lvitem);
m_wndView.SetItemText(i, 1, TEXT("1")); m_wndView.SetItemText(i, 2, TEXT("2")); } return TRUE; }
SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (0 == SHGetFileInfo(TEXT("*.rxs"), FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)) { AfxMessageBox(TEXT("Failed")); } int idx = m_imageList.Add(shfi.hIcon); if (0 == SHGetFileInfo(TEXT("*.doc"), FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)) { AfxMessageBox(TEXT("Failed")); } m_imageList.Add(shfi.hIcon); m_wndList.InsertItem(1, TEXT("dd"), idx); m_wndList.InsertItem(2, TEXT("test"), idx + 1);
InsertItem Return Value The index of the new item if successful or - 1 otherwise.
BOOL DeleteItem(int nItem); Return Value Nonzero if successful; otherwise zero.
插入项带图标 nt idx = m_imageList.Add(shfi.hIcon); m_wndList.InsertItem(1, TEXT("dd"), idx);
|