zoukankan
html css js c++ java
如何获取文件在系统中的图标?
public
class
SysIO2
{
public
SysIO2()
{
}
private
const
uint
SHGFI_ICON
=
0x100
;
private
const
uint
SHGFI_LARGEICON
=
0x0
;
private
const
uint
SHGFI_SMALLICON
=
0x1
;
public
const
uint
SHGFI_USEFILEATTRIBUTES
=
0x10
;
[DllImport(
"
kernel32.dll
"
)]
internal
static
extern
void
ExitProcess(
int
a);
[DllImport(
"
shell32.dll
"
)]
private
static
extern
IntPtr SHGetFileInfo(
string
pszPath,
uint
dwFileAttributes,
ref
SHFILEINFO psfi,
uint
cbSizeFileInfo,
uint
uFlags);
[StructLayout(LayoutKind.Sequential)]
private
struct
SHFILEINFO
{
public
IntPtr hIcon;
public
IntPtr iIcon;
public
uint
dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst
=
260
)]
public
string
szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst
=
80
)]
public
string
szTypeName;
}
/**/
///
<summary>
///
获取指定文件(或者扩展名)和系统关联的小图标
///
</summary>
///
<param name="strExtension">
文件名,或者文件扩展名(.bmp等等)
</param>
///
<returns></returns>
internal
static
Icon GetSmallIcon(
string
strExtension)
{
string
strFileName
=
Path.GetExtension(strExtension);
if
(strFileName
==
""
)
{
strFileName
=
strExtension;
}
IntPtr hImgSmall;
SHFILEINFO shinfo
=
new
SHFILEINFO();
hImgSmall
=
SHGetFileInfo(strFileName,
0
,
ref
shinfo, (
uint
)Marshal.SizeOf(shinfo), SHGFI_ICON
|
SHGFI_SMALLICON
|
SHGFI_USEFILEATTRIBUTES);
Icon myIcon
=
System.Drawing.Icon.FromHandle(shinfo.hIcon);
return
myIcon;
}
/**/
///
<summary>
///
获取指定文件(或者扩展名)和系统关联的大图标
///
</summary>
///
<param name="strExtension">
文件名,或者文件扩展名(.bmp等等)
</param>
///
<returns></returns>
internal
static
Icon GetLargeIcon(
string
strExtension)
{
string
strFileName
=
Path.GetExtension(strExtension);
if
(strFileName
==
""
)
{
strFileName
=
strExtension;
}
IntPtr hImgLarge;
SHFILEINFO shinfo
=
new
SHFILEINFO();
hImgLarge
=
SHGetFileInfo(strFileName,
0
,
ref
shinfo, (
uint
)Marshal.SizeOf(shinfo), SHGFI_ICON
|
SHGFI_LARGEICON
|
SHGFI_USEFILEATTRIBUTES);
Icon myIcon
=
System.Drawing.Icon.FromHandle(shinfo.hIcon);
return
myIcon;
}
}
查看全文
相关阅读:
selenium 操作过程中,元素标红高亮的两种实现方式
python pytest测试框架介绍五---日志实时输出
pytest 3.9在python 2.7下的一个bug
Qt assis tant 帮助集合文档 -由.qhcp生成.qhc
Qt assistant .qch显示乱码问题
qhelpgenerator 由qhp生成qch过程碰到的问题 记录
Qt creator新建widget项目....no valid kits found.....
Qt creator 账号
Qt 写Excel
Qt获取主窗口
原文地址:https://www.cnblogs.com/dreign/p/627146.html
最新文章
date
wget
useradd groupadd passwd usermod userdel chfn id
记一次海康威视的面试经历
effictive-python笔记
代码中的坏味道-重构改善既有代码的设计
go的基结构体如何使用派生结构体的方法
面对对象设计需要遵循的原则
23种设计模式
简单工厂模式,工厂方法模式,抽象工厂模式的区别
热门文章
(转)看懂UML类图和时序图
ubuntu14.04上编译安装python3.7.3
mysql必知必会(四、检索数据,五、排序检索数据,六、过滤数据,七、数据过滤)
jenkins git 之 Advanced clone behaviours
python nose 自写插件支持用例带进度
python nose测试框架全面介绍十二 ----用例执行顺序打乱
jenkins之 Throttle Concurrent Builds使用
python nose测试框架全面介绍十一---用例的发现
python unittest addCleanup中也加失败截图功能
Jmeter中使用SSH插件,连接远程linux机器执行命令
Copyright © 2011-2022 走看看