windows桌面是怎么绘制的

cc___999 2016-12-26 04:29:57
开发一个扩展,需要模拟explorer绘制图标,就想参考下windows的桌面是怎么绘制的

快捷方式还好,像.xlsx文件显示的是excel图标,.rar显示的是winrar图标,这个是找到默认打开程序的图标绘制的?

还有文件夹,他会预览显示文件夹里的文件类型:如,这个是怎么实现的?
...全文
504 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2017-02-09
  • 打赏
  • 举报
回复
我的win7上 并没有这种图标!
「已注销」 2017-02-08
  • 打赏
  • 举报
回复
引用 8 楼 schlafenhamster 的回复:
"显示内置文件图标的问题"
shell32.dll 里有没有 这个图标 ?
楼主那个截图,就是 Windows Vista、7 等系统上的文件夹图标,如图:这种根据文件夹内容显示不同的图标,无解,微软都没开放。除此之外,全部用 SHGetFileInfo 来解决。
schlafenhamster 2017-02-06
  • 打赏
  • 举报
回复
"显示内置文件图标的问题" shell32.dll 里有没有 这个图标 ?
「已注销」 2017-02-06
  • 打赏
  • 举报
回复
并没有解决文件夹图标中像书一样显示内置文件图标的问题,而获取其他文件或者系统文件夹的图标,核心还是用 SHGetFileInfo,可以根据 LPITEMIDLIST 或者路径来获取。
赵4老师 2017-01-16
  • 打赏
  • 举报
回复
搜“Shell Extension”
schlafenhamster 2017-01-16
  • 打赏
  • 举报
回复
调用

////
void CMyExploreView::PopulateList(LPTVITEMDATA lptvid) 
{//from lptvid->lpsfparent->current_folder
	LPSHELLFOLDER lpsf2=NULL;
    HRESULT hr;
// Initialize the list view to be empty.
	CListCtrl    &RightList=GetListCtrl();
    RightList.DeleteAllItems();
// ask for current folder
    if (lptvid)
    {
		hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
			0, IID_IShellFolder,(LPVOID *)&lpsf2);
		if (SUCCEEDED(hr))
		{// current dir oK
			FillListView(lpsf2,lptvid->lpifq);// 
			lpsf2->Release();
		//  then sorting
			RightList.SortItems(ListViewCompareProc,0);// name
		}
	}
}
schlafenhamster 2017-01-16
  • 打赏
  • 举报
回复
注意 GetNormalIcons(
schlafenhamster 2017-01-16
  • 打赏
  • 举报
回复
参考:

void CMyExploreView::FillListView(LPSHELLFOLDER lpsf,LPITEMIDLIST lpifq)
{
    LVITEM          lvi;      // ListView Item.
    LPENUMIDLIST    lpe=NULL;
    LPITEMIDLIST    lpi=NULL,lpifqThisItem=NULL;
    LPLVITEMDATA    lplvid=NULL;
    LPMALLOC        lpMalloc=NULL;
    ULONG           ulFetched;
    UINT            uCount=0;
    HRESULT         hr;
    char            szBuff[256];
    HWND            hwnd=::GetParent(m_hWnd);
//	char            tmp[256];
//
	CListCtrl    &RightList=GetListCtrl();
// Allocate a shell memory object. 
    hr=::SHGetMalloc(&lpMalloc);
    if (FAILED(hr)) return;
    if (SUCCEEDED(hr))
    {// Get the IEnumIDList object for the given folder.
        hr=lpsf->EnumObjects(hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &lpe);
        if (SUCCEEDED(hr))
        {// Enumerate throught the list of folder and non-folder objects.
            while (S_OK==lpe->Next(1, &lpi, &ulFetched))
            {   
                ULONG ulAttrs = SFGAO_FOLDER;
                // Determine what type of object we have.
                lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpi, &ulAttrs);
				lvi.iItem=uCount;
				lvi.iSubItem=0;
                lvi.mask= LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
                //OK, let's get some memory for our ITEMDATA struct
                lplvid = (LPLVITEMDATA)lpMalloc->Alloc(sizeof(LVITEMDATA));
                if (!lplvid) goto Done;  // Error - could not allocate memory.
                //Now get the friendly name that we'll put in the treeview.
                if (!GetName(lpsf, lpi, SHGDN_NORMAL, szBuff))
                     goto Done; // Error - could not get friendly name.
                lvi.pszText    = szBuff;
                lvi.cchTextMax = MAX_PATH;
				//Now, make a copy of the ITEMIDLIST
				//They are used in compareproc 
                lplvid->lpi=CopyITEMID(lpMalloc, lpi);
				//SHGetFileInfo() needs a full pidl.
                lpifqThisItem=ConcatPidls(lpifq,lpi);
				GetNormalIcons(lpifqThisItem,&lvi);// ICON
	            //
				lplvid->lpsfParent=lpsf;//Store the parent folders SF
                lpsf->AddRef();
                lplvid->lpifq=ConcatPidls(lpifq,lpi);
                lvi.lParam = (LPARAM)lplvid;
				// Add the item to the list
				RightList.InsertItem(&lvi);
// add sub items. size//?? GetDetailsOf();
				WIN32_FIND_DATA fd;//relative lpi
				hr=SHGetDataFromIDList(lpsf,lpi,SHGDFIL_FINDDATA,&fd,sizeof(fd));				
//				if (FAILED(hr)) return;
				__int64 AllSize=fd.nFileSizeHigh;
				AllSize<<=32;
				AllSize+=fd.nFileSizeLow;
				char tmp[MAX_PATH];
				BOOL bl=0;
                if (!(ulAttrs & SFGAO_FOLDER))
				{// dir no size be shown
					FileSizeGB((double)AllSize,tmp);
					bl=RightList.SetItemText(uCount,1,tmp);
				}
// type
				SHFILEINFO	sfi;
				::SHGetFileInfo((LPCTSTR)lpifqThisItem,0,&sfi,sizeof(SHFILEINFO),SHGFI_PIDL|SHGFI_TYPENAME);
				BOOL ret=RightList.SetItemText(uCount,2,sfi.szTypeName);	
// time
				SYSTEMTIME st;
				FileTimeToSystemTime(&fd.ftLastWriteTime,&st);
				sprintf(tmp,"%2.2hd/%2.2hd/%4.4hd  %2.2hd:%2.2hd",
				st.wMonth,st.wDay,st.wYear,st.wHour,st.wMinute);
				bl=RightList.SetItemText(uCount,3,tmp);	
//Free task allocator
                lpMalloc->Free(lpifqThisItem);  
                lpifqThisItem=0;
// Free this items task allocator.
                lpMalloc->Free(lpi);  //Free the pidl that the shell gave us.
                lpi=0;
				uCount++;
            }
        }// end if success
    }
    else
       return;
Done:
    if (lpe) lpe->Release();
    //The following 2 if statements will only be TRUE if we got here on an
    //error condition from the "goto" statement.  Otherwise, we free this memory
    //at the end of the while loop above.
    if (lpi && lpMalloc) lpMalloc->Free(lpi);
    if (lpMalloc) lpMalloc->Release();
    if (lpifqThisItem && lpMalloc) lpMalloc->Free(lpifqThisItem);  
}
void CMyExploreView::GetNormalIcons(LPITEMIDLIST lpifq,LPLVITEM lplvitem)
{
   //Note that we don't check the return value here because if GetIcon()
   //fails, then we're in big trouble...
   lplvitem->iImage = GetItemIcon(lpifq, SHGFI_PIDL | 
                              SHGFI_SYSICONINDEX | 
                              SHGFI_SMALLICON);
   return;
}
「已注销」 2017-01-14
  • 打赏
  • 举报
回复
各种文件的图标,你可以用 SHGetFileInfo 来获取系统图像列表中的索引,进而绘制。但是文件夹中分多层显示其中包含的文件图标,这个目前系统没有开放(据我所知),还是不太好办的。
oyljerry 2016-12-26
  • 打赏
  • 举报
回复
都是找到对应的icon文件,然后来显示 文件夹的icon属于系统。在shell32.dll中有资源

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧