- 积分
- 3334
- 明经币
- 个
- 注册时间
- 2016-6-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2018-9-26 16:40:23
|
显示全部楼层
本帖最后由 zjh2785 于 2018-9-26 16:41 编辑
找到了 只是只可以找出部分 ,在CAD安装目录下有一些文件名包含“res”特定名称的dll存在图标 , 比如:xxxxres.dll 有很多 ,可以一一尝试, 以下代码仅供参考:
- /// <summary>
- /// 获取文件中的图标
- /// </summary>
- /// <param name="fileName">dll或者exe文件名,如果在CAD安装目录、系统目录或是其他支持的目录</param>
- /// <param name="iconIndex">图标索引 起始值为0</param>
- /// <param name="size">图标尺寸 64x64 32x32 16x16 都可以 int型 64 代表64x64,也可以在函数内自己设定不等边尺寸</param>
- /// <returns></returns>
- public System.Drawing.Icon GetIcon(string fileName, int iconIndex, Size size)
- {
- try
- {
- var iconTotalCount = PrivateExtractIcons(fileName, 0, 0, 0, null, null, 0, 0);
- if (iconTotalCount > 0 && iconIndex <= iconTotalCount)
- {
- IntPtr[] hIcons = new IntPtr[1];
- int[] ids = new int[iconIndex];
- var successCount = PrivateExtractIcons(fileName, iconIndex, size.Width, size.Height, hIcons, ids, 1, 0);
- if (successCount > 0 && hIcons[0] != IntPtr.Zero)
- {
- System.Drawing.Icon result = System.Drawing.Icon.FromHandle(hIcons[0]);
- return result;
- }
- }
- return null;
- }
- catch
- {
- return null;
- }
- }
复制代码- [DllImport("User32.dll")]
- public static extern int PrivateExtractIcons(
- string lpszFile, //file name
- int nIconIndex, //The zero-based index of the first icon to extract.
- int cxIcon, //The horizontal icon size wanted.
- int cyIcon, //The vertical icon size wanted.
- IntPtr[] phicon, //(out) A pointer to the returned array of icon handles.
- int[] piconid, //(out) A pointer to a returned resource identifier.
- int nIcons, //The number of icons to extract from the file. Only valid when *.exe and *.dll
- int flags //Specifies flags that control this function.
- );
复制代码
测试代码:
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- System.Drawing.Size size = new Size();
- size.Width = Convert.ToInt32(numericUpDown1.Value);
- size.Height = size.Width;
- pictureBox1.Image = GetIcon(this.textBox1.Text, int.Parse(textBox2.Text), size).ToBitmap();
- }
- catch
- { }
- }
|
|