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;
}
}
查看全文
相关阅读:
.net反编译原理
科学使用Log4View2
头条一面竟然问我Maven?
SpringCloud Netflix(一) :微服务架构
Linux环境安装Docker
Quartz定时任务
Jedis连接外部Redis
宝塔phpmyadmin打不开的可能问题及解决方法
文件上传 Window & Linux
SpringBoot登录判断
原文地址:https://www.cnblogs.com/dreign/p/627146.html
最新文章
Java vs c++ 字符串 vector ArrayList 迭代器数组比较
iOS RSA Der-加密 P12-解密以及配合AES使用详解
FMDB大量写入数据使用注意点
常用开发技巧系列(五)
Cocos2d-Lua 做一个活动转盘
Carthage 不知不觉用到了
Cocos2dx-Lua UIScrollView 和 UITableView 对比
Android学习--还有一些小技巧
Android学习--探究服务(二)
Android学习--探究服务(一)
热门文章
小姐姐教你定制一个Logstash Java Filter
这么简单的ES索引生命周期管理,不了解一下吗~
托管对象本质-第一部分-布局
NIO-FileChannel源码分析
NIO-SocketChannel源码分析
NIO-Channel接口分析
I/O中断原理
NIO-Channel
NIO-Buffer
NIO-概览
Copyright © 2011-2022 走看看