Windows系统SHELL图标获取的功能类分享
2021-03-03 21:27
标签:name 文件信息 filename family list pen let 文件 hicon - 可以获取系统图标列表 - 可以获取任意文件/文件夹/磁盘的图标 - 可以获取任意文件/文件夹/磁盘图标在系统图标列表中的位置 Windows系统SHELL图标获取的功能类分享 标签:name 文件信息 filename family list pen let 文件 hicon 原文地址:https://www.cnblogs.com/veis/p/12962190.html1.用途
2.头文件
#pragma once
#include
3.源文件
#include "pch.h"
#include "CSHGetFileInfo.h"
HIMAGELIST CSHGetFileInfo::GetSystemImageListHandle(BOOL bSmallIcon)
{
HIMAGELIST hSystemImageList;
SHFILEINFO ssfi;
if (bSmallIcon)
{
hSystemImageList = (HIMAGELIST)SHGetFileInfo( (LPCTSTR)_T("c:\\"), 0, &ssfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
}
else
{
hSystemImageList = (HIMAGELIST)SHGetFileInfo( (LPCTSTR)_T("c:\\"), 0, &ssfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
}
return hSystemImageList;
}
int CSHGetFileInfo::GetFileIconIndex(CString strFileName, BOOL bSmallIcon)
{
SHFILEINFO sfi;
if (bSmallIcon)
{
SHGetFileInfo( (LPCTSTR)strFileName, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
}
else
{
SHGetFileInfo( (LPCTSTR)strFileName, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES);
}
return sfi.iIcon;
}
int CSHGetFileInfo::GetDirIconIndex(BOOL bSmallIcon)
{
SHFILEINFO sfi;
if (bSmallIcon)
{
SHGetFileInfo( (LPCTSTR)_T("Doesn‘t matter"), FILE_ATTRIBUTE_DIRECTORY, &sfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
}
else
{
SHGetFileInfo( (LPCTSTR)_T("Doesn‘t matter"), FILE_ATTRIBUTE_DIRECTORY, &sfi,
sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES);
}
return sfi.iIcon;
}
int CSHGetFileInfo::GetDiskIconIndex(LPCTSTR diskName, BOOL bSmallIcon)
{
SHFILEINFO sfi;
DWORD attr = ::GetFileAttributes(diskName);
if (bSmallIcon)
{
::SHGetFileInfo(diskName, attr, &sfi, sizeof(sfi),
SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); //获取文件信息
}
else
{
::SHGetFileInfo(diskName, attr, &sfi, sizeof(sfi),
SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES); //获取文件信息
}
return sfi.iIcon;
}
HICON CSHGetFileInfo::GetFileIconHandle(CString strFileName, BOOL bSmallIcon)
{
SHFILEINFO sfi;
if (bSmallIcon)
{
SHGetFileInfo( (LPCTSTR)strFileName, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
}
else
{
SHGetFileInfo( (LPCTSTR)strFileName, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES);
}
return sfi.hIcon;
}
HICON CSHGetFileInfo::GetFolderIconHandle(BOOL bSmallIcon)
{
SHFILEINFO sfi;
if (bSmallIcon)
{
SHGetFileInfo( (LPCTSTR)_T("Doesn‘t matter"), FILE_ATTRIBUTE_DIRECTORY, &sfi,
sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
}
else
{
SHGetFileInfo( (LPCTSTR)_T("Doesn‘t matter"), FILE_ATTRIBUTE_DIRECTORY, &sfi,
sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES);
}
return sfi.hIcon;
}
HICON CSHGetFileInfo::GetDiskIconHandle(LPCTSTR diskName, BOOL bSmallIcon)
{
SHFILEINFO sfi;
DWORD attr = ::GetFileAttributes(diskName);
if (bSmallIcon)
{
::SHGetFileInfo(diskName, attr, &sfi, sizeof(sfi),
SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES); //获取文件信息
}
else
{
::SHGetFileInfo(diskName, attr, &sfi, sizeof(sfi),
SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES); //获取文件信息
}
return sfi.hIcon;
}
CString CSHGetFileInfo::GetFileType(CString strFileName)
{
SHFILEINFO sfi;
SHGetFileInfo((LPCTSTR)strFileName, FILE_ATTRIBUTE_NORMAL, &sfi,
sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);
return sfi.szTypeName;
}
文章标题:Windows系统SHELL图标获取的功能类分享
文章链接:http://soscw.com/index.php/essay/59690.html