WinCE如何获得所有文件夹信息,用SHGetFileInfo()怎么获取不到啊,
就是做个类似windows资源管理器,分左右2边,TreeView,ListView. Wince 资源管理器
[解决办法]
void FileViewDlg::EnumFiles(LPCTSTR pszPath, LPCTSTR pszFilter)
{
WIN32_FIND_DATAfd;
HANDLEhFind;
BOOLbFind;
CStringstrSearch(pszPath),
strFile;
inti = m_listFile.GetItemCount();
LVITEM lvItem;
COleDateTimeodt;
//CDateTimeFormatdtf;
CWaitCursorwait;
//
// Flush the list
//
//m_listFile.DeleteAllItems();
//m_cont.clear();
//
// Fill in the list
//
strSearch += pszFilter;
hFind = FindFirstFile(strSearch, &fd);
bFind = (hFind != INVALID_HANDLE_VALUE);
//
// Disable painting the list
//
while(bFind)
{
if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
strFile = pszPath;
strFile += fd.cFileName;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText = (LPTSTR)(LPCTSTR)(fd.cFileName);
lvItem.mask = LVIF_TEXT
[解决办法]
LVIF_IMAGE
[解决办法]
LVIF_PARAM;
lvItem.iImage = GetIconIndex(strFile);
lvItem.lParam = 0;
m_listFile.InsertItem(&lvItem);
//if(iItem != -1)
//{
//
// Format size according to locale
//
//m_listFile.SetItemText(iItem, 1, FormatSize(fd.nFileSizeLow));
////
//// Format date according to locale
////
//odt = fd.ftLastWriteTime;
//dtf.SetDateTime(odt);
//dtf.SetFormat(m_strDateFormat);
//m_listFile.SetItemText(iItem, 2, dtf.GetString());
//m_listFile.SetItemData(iItem, i);
m_cont.push_back(fd);
//}
i++;
}
bFind = FindNextFile(hFind, &fd);
}
DoSortList();
//
// Enable painting the list
//
}
int FileViewDlg::EnumDirs(LPCTSTR pszPath, LPCTSTR pszFilter)
{
WIN32_FIND_DATAfd;
HANDLEhFind;
BOOLbFind;
//HTREEITEMhItem = TVI_LAST;
CStringstrSearch(pszPath),
strBase(pszPath);
intnCount= m_listFile.GetItemCount();
LVITEM lvItem;
strSearch += pszFilter;
hFind = FindFirstFile(strSearch, &fd);
bFind = (hFind != INVALID_HANDLE_VALUE);
while(bFind)
{
if((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
//TVINSERTSTRUCTtvi;
//CStringstrSub(strBase);
//intiIcon;
//strSub += fd.cFileName;
//iIcon = GetIconIndex(strSub);
// tvi.hParent= hItemParent;
// tvi.hInsertAfter= TVI_LAST;
// tvi.item.mask= TVIF_CHILDREN
[解决办法]
TVIF_IMAGE
[解决办法]
TVIF_SELECTEDIMAGE
[解决办法]
// TVIF_TEXT
[解决办法]
TVIF_PARAM;
// tvi.item.pszText= fd.cFileName;
// tvi.item.iImage= iIcon;
// tvi.item.iSelectedImage= iIcon;
// tvi.item.cChildren= I_CHILDRENCALLBACK;
// tvi.item.lParam= -1;
//hItem = m_treeFolder.InsertItem(&tvi);
lvItem.iItem = nCount;
lvItem.iSubItem = 0;
lvItem.pszText = (LPTSTR)(LPCTSTR)(fd.cFileName);
lvItem.mask = LVIF_TEXT
[解决办法]
LVIF_IMAGE
[解决办法]
LVIF_PARAM;
lvItem.iImage = GetIconIndex(strBase + fd.cFileName);
lvItem.lParam = 1;
m_listFile.InsertItem(&lvItem);
++nCount;
/*
strSub += _T("\");
if(hItem)
{
m_treeFolder.SetItemData(hItem, 1);
EnumDirs(strSub, pszFilter, hItem);
}*/
}
bFind = FindNextFile(hFind, &fd);
}
return nCount;
}
LRESULT CALLBACK TwoStateFileAnimProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LPCTSTR szFileName = TEXT("myfile.xls");
LRESULT lRet = 0;
static SHFILEINFO s_sfiLarge = {0};
static SHFILEINFO s_sfiLargeSelected = {0};
static HIMAGELIST s_himlLarge = NULL;
static HIMAGELIST s_himlLargeSelected = NULL;
switch (message)
{
case WM_CREATE:
// Cache the file information and the imagelist.
// Get the large default icon for the file.
s_himlLarge = (HIMAGELIST)SHGetFileInfo(szFileName, 0, &s_sfiLarge, sizeof(s_sfiLarge), SHGFI_SYSICONINDEX
[解决办法]
SHGFI_LARGEICON);
// Get the large selected icon for the file.
s_himlLargeSelected = (HIMAGELIST)SHGetFileInfo(szFileName, 0, &s_sfiLargeSelected, sizeof(s_sfiLargeSelected), SHGFI_SYSICONINDEX
[解决办法]
SHGFI_LARGEICON
[解决办法]
SHGFI_SELECTICON);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Draw the file icon in the selected state.
ImageList_Draw(s_himlLargeSelected, s_sfiLargeSelected.iIcon, hdc, 0, 0, ILD_TRANSPARENT);
// Draw the file icon in the default state.
ImageList_Draw(s_himlLarge, s_sfiLarge.iIcon, hdc, 0, 100, ILD_TRANSPARENT);
EndPaint(hwnd, &ps);
break;
}
}
return lRet;
}