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;
}
}
查看全文
相关阅读:
mysql通过一张表更新另一张表
申请微信支付填错对公账号的解决办法
radio 实现点击两次 第一次点击选中第二次点击取消
C#修改下拉框选项的高度
Centos7 用yum命令安装LAMP环境(php+Apache+Mysql)以及php扩展
php备份数据库
windows环境下 composer 的安装与使用
PHP获取多维数据的交集与差集
JS 图片懒加载
搭建 window + nginx + php 开发环境
原文地址:https://www.cnblogs.com/dreign/p/627146.html
最新文章
webservice soap axis2客户端接口开发
将xml字符串的所有叶标签转换成Map集合
线程池总结
1.3.4 Fork/Join框架
1.3.4 并发工具类CountDownLatch/Semaphore/CyclicBarrier/FutureTask
1.3.3 并发容器类MAP/LIST/SET/QUEUE
1.3.2 AQS 读写锁
java8特性 list去重
vue开发 使用时间组件
sql常用到的查询连接
热门文章
java知识随笔整理-Oracle存储过程优缺点
java知识随笔整理-标量函数和表值函数
java知识随笔整理-数据库的临时表
ActiveMQ 即时通讯服务 入門指南及淺析
Net4.0 framework4.0 安装失败的解决方法 已成功安装
js点击发送验证码 xx秒后重新发送
Mysql 备份数据库方法及when using LOCK TABLES错误解决方法
php FastCGI 进程意外退出 错误解决方法
网站视频不能播放,报错net::ERR_CONNECTION_ABORTED
phpmyadmin登录报错crypt_random_string requires at least one symmetric cipher be loaded 解决方法
Copyright © 2011-2022 走看看