如何获取"我的电脑"的图标?

javaduke 2002-02-07 11:18:12
用什么函数。
SHGetFileInfo好像不可以。
请帮忙。
...全文
549 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizer 2002-02-09
  • 打赏
  • 举报
回复
int GetDesktopIcon(HWND hWnd, BOOL bSmall)
{
SHFILEINFO shFi;
LPSHELLFOLDER lpsf=NULL;
LPCITEMIDLIST lpi=NULL;
LPENUMIDLIST lpe=NULL;
ULONG lValue = 0;
HRESULT hr;
hr = SHGetDesktopFolder(&lpsf);
if(!SUCCEEDED(hr))
{
return -1;
}

hr = lpsf->EnumObjects(hWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &lpe);
if(!SUCCEEDED(hr))
{
return -1;
}

if(S_OK != lpe->Next(1, (struct _ITEMIDLIST **)&lpi, &lValue))
{
return -1;
}

ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpi, &ulAttrs);

if( SHGetFileInfo((LPCSTR)lpi, 0, &shFi, sizeof(SHFILEINFO),
SHGFI_PIDL | SHGFI_SYSICONINDEX
| (bSmall ? SHGFI_SMALLICON : SHGFI_ICON)) == 0)
{
return -1;
}
DestroyIcon(shFi.hIcon);
return = shFi.iIcon;
}
这个函数就可得到我的电脑的图标的索引值了,不管你是不是使用了桌面主题都可以拿到
这里的ImageList 与 panda_w(好想睡啊!) 所得到的是同一个。

不知道你是不是要这样的。
weixiao 2002-02-09
  • 打赏
  • 举报
回复
在windows系列的系统目录下,
都有一个shell32.dll
这个DLL中包含许多操作系统用到的和未用到的图标,
你可以从中提取:)

浏览的方法:
右击快捷方式-》属性-》更改图标-》浏览-》打开(系统目录下的shell32.dll),你就可看到这个DLL中包含的图标了:)
panda_w 2002-02-09
  • 打赏
  • 举报
回复
贴代码了
问题:请问我在VC中怎么得到文件的图标呢?Exe文件的图标好得到,但那些应用程序的文件的图标怎么得到呢?例如,类似于Windows的资源管理器,怎么得到它的关联图标呢,例如:.mp3的文件的图标,从哪里得到呢?
tomPeakz(张子) 回复于2002-1-28 9:40:28 得60分删除回复
不难,要使用系统的API,如下示例:
// CTreeListFileDlg dialog

int CSystemImageList::m_nRefCount=0;

//////////////////////////////CSystemImageList Implementation /////////////////////////////////

CSystemImageList::CSystemImageList()
{
if (m_nRefCount == 0)
{
//Attach to the system image list
SHFILEINFO sfi;
HIMAGELIST hSystemImageList = (HIMAGELIST) SHGetFileInfo(_T("\\"), 0, &sfi, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
VERIFY(m_ImageList.Attach(hSystemImageList));
}

//Increment the reference count
m_nRefCount++;
}

CSystemImageList::~CSystemImageList()
{
//Decrement the reference count
m_nRefCount--;

if (m_nRefCount == 0)
{
//Detach from the image list to prevent problems on 95/98 where
//the system image list is shared across processes
m_ImageList.Detach();
}
}

CImageList& CSystemImageList::GetImageList()
{
return m_ImageList;
}


BOOL CTreeListFileDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
m_csFilter = _T("All Files (*.*)");
UpdateData(FALSE);
//设置系统图标
m_ctlFileTree.SetImageList(&m_SysImageList.GetImageList(),TVSIL_NORMAL);
OnViewRefresh();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

int CTreeListFileDlg::GetIconIndex(HTREEITEM hItem)
{
TV_ITEM tvi;
ZeroMemory(&tvi, sizeof(TV_ITEM));
tvi.mask = TVIF_IMAGE;
tvi.hItem = hItem;
if (m_ctlFileTree.GetItem(&tvi))
return tvi.iImage;
else
return -1;
}

int CTreeListFileDlg::GetIconIndex(const CString& sFilename)
{
//Retreive the icon index for a specified file/folder
SHFILEINFO sfi;
if (SHGetFileInfo(sFilename, 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON) == 0)
return -1;
return sfi.iIcon;
}
tg123 2002-02-09
  • 打赏
  • 举报
回复
%windir&\explore.exe

拿出来就行了
strip 2002-02-09
  • 打赏
  • 举报
回复
ExtractIcon和ExtractIconEx, Explorer.exe里面有我的电脑的icon,nIndex=0

msdn里面有sample code (Q185883,vb)
BaoYu 2002-02-08
  • 打赏
  • 举报
回复
帮你UP一下吧.呵呵,可要给分哦.
javaduke 2002-02-08
  • 打赏
  • 举报
回复
怎么没有回答?
没有人知道吗?
太可惜了。

1,658

社区成员

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

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