明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1150|回复: 8

[界面] 求助:有什么方法直接获取CAD自带的图标呢?

[复制链接]
发表于 2018-8-24 14:51 | 显示全部楼层 |阅读模式
CAD自带的图标有很多,有的时候可以用的上,有没有什么方法可以根据图像的名字直接获取指定的图标呢?

一直找不到CAD自带图标是放在哪个文件夹。



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2018-9-16 20:20 | 显示全部楼层
楼主找到方法了吗?
发表于 2018-9-17 21:51 | 显示全部楼层
直接编辑,然后输出就可以了
 楼主| 发表于 2018-9-26 16:32 | 显示全部楼层
j15tty 发表于 2018-9-17 21:51
直接编辑,然后输出就可以了

谢谢 ,不过我是想要在程序运行的过程中直接获取图标, 目前已经找到一个方法。可以获取部分图标。其他图标不知道存在于哪个DLL文件里面
 楼主| 发表于 2018-9-26 16:40 | 显示全部楼层
本帖最后由 zjh2785 于 2018-9-26 16:41 编辑
红黑墨水 发表于 2018-9-16 20:20
楼主找到方法了吗?

找到了 只是只可以找出部分 ,在CAD安装目录下有一些文件名包含“res”特定名称的dll存在图标  , 比如:xxxxres.dll  有很多 ,可以一一尝试, 以下代码仅供参考:
  1.         /// <summary>
  2.         /// 获取文件中的图标
  3.         /// </summary>
  4.         /// <param name="fileName">dll或者exe文件名,如果在CAD安装目录、系统目录或是其他支持的目录</param>
  5.         /// <param name="iconIndex">图标索引 起始值为0</param>
  6.         /// <param name="size">图标尺寸 64x64 32x32 16x16 都可以 int型  64  代表64x64,也可以在函数内自己设定不等边尺寸</param>
  7.         /// <returns></returns>
  8.         public System.Drawing.Icon GetIcon(string fileName, int iconIndex, Size size)
  9.         {
  10.             try
  11.             {
  12.                 var iconTotalCount = PrivateExtractIcons(fileName, 0, 0, 0, null, null, 0, 0);
  13.                 if (iconTotalCount > 0 && iconIndex <= iconTotalCount)
  14.                 {
  15.                     IntPtr[] hIcons = new IntPtr[1];
  16.                     int[] ids = new int[iconIndex];
  17.                     var successCount = PrivateExtractIcons(fileName, iconIndex, size.Width, size.Height, hIcons, ids, 1, 0);
  18.                     if (successCount > 0 && hIcons[0] != IntPtr.Zero)
  19.                     {
  20.                         System.Drawing.Icon result = System.Drawing.Icon.FromHandle(hIcons[0]);
  21.                         return result;
  22.                     }
  23.                 }
  24.                 return null;
  25.             }
  26.             catch
  27.             {
  28.                 return null;
  29.             }
  30.         }
复制代码
  1.         [DllImport("User32.dll")]
  2.         public static extern int PrivateExtractIcons(
  3.             string lpszFile, //file name
  4.             int nIconIndex,  //The zero-based index of the first icon to extract.
  5.             int cxIcon,      //The horizontal icon size wanted.
  6.             int cyIcon,      //The vertical icon size wanted.
  7.             IntPtr[] phicon, //(out) A pointer to the returned array of icon handles.
  8.             int[] piconid,   //(out) A pointer to a returned resource identifier.
  9.             int nIcons,      //The number of icons to extract from the file. Only valid when *.exe and *.dll
  10.             int flags        //Specifies flags that control this function.
  11.         );
复制代码


测试代码:
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 System.Drawing.Size size = new Size();
  6.                 size.Width = Convert.ToInt32(numericUpDown1.Value);
  7.                 size.Height = size.Width;
  8.                 pictureBox1.Image = GetIcon(this.textBox1.Text, int.Parse(textBox2.Text), size).ToBitmap();
  9.             }
  10.             catch
  11.             { }
  12.         }
发表于 2018-9-26 20:38 | 显示全部楼层
楼主研究的真深
发表于 2018-9-27 10:54 | 显示全部楼层
zjh2785 发表于 2018-9-26 16:40
找到了 只是只可以找出部分 ,在CAD安装目录下有一些文件名包含“res”特定名称的dll存在图标  , 比如: ...

好厉害,试着保存了一下,图标比较模糊,有什么解决办法吗
 楼主| 发表于 2018-9-27 11:17 | 显示全部楼层
ps122hb 发表于 2018-9-27 10:54
好厉害,试着保存了一下,图标比较模糊,有什么解决办法吗

有些dll立面的文件本身就是16x16的  你用64x64的输出  肯定会模糊
发表于 2018-9-28 08:24 | 显示全部楼层
zjh2785 发表于 2018-9-27 11:17
有些dll立面的文件本身就是16x16的  你用64x64的输出  肯定会模糊

就是选的16X16也模糊,找了个工具导出效果还不错
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-28 22:38 , Processed in 0.178810 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表