主题:[讨论]这些功能是怎么实现的?
yujimin
[专家分:0] 发布于 2008-09-09 17:33:00
这些功能是如何实现的呢?
在 图片里的 “输出目录”的框框里输入目标文件夹(如果没有文件夹可以新建一个,就是说在可以这样 C:\ICO)后 点击“导出”按钮后所有的图标就在文件夹里了,是原汁原味的图标.对了,可以提取 exe 和 dll文件袋图标。
谢谢大家!
PS:为什么不能上传图片?
最后更新于:2008-10-16 07:22:00
回复列表 (共10个回复)
沙发
一江秋水 [专家分:9680] 发布于 2008-09-10 16:24:00
楼主想得轻松,想得美,呵呵。。。
不过,幸好碰到了我,我的一个爱好就是成人之美。
先在你的 D 盘上新建一个 Icons 文件夹。
代码如下:
Option Explicit
Private Type PICTDESC
Size As Long
Type As Long
hBmpOrIcon As Long
hPal As Long
End Type
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PICTDESC, riid As Any, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Sub Command1_Click()
Dim i As Integer, IconCount As Integer, ihdc As Long, aGuid(0 To 3) As Long
Dim OpenName As String, SaveName As String
Dim lpPictDesc As PICTDESC, NewIco As IPicture, Pic As StdPicture
OpenName = "%SystemRoot%\system32\SHELL32.dll" '这个文件中有237个图标
IconCount = ExtractIcon(0, OpenName, -1)
If IconCount = 0 Then MsgBox "该文件不含图标": Exit Sub
For i = 1 To IconCount
ihdc = ExtractIcon(0, OpenName, i)
If ihdc Then
lpPictDesc.Size = Len(lpPictDesc)
lpPictDesc.Type = vbPicTypeIcon
lpPictDesc.hBmpOrIcon = ihdc
aGuid(0) = &H7BF80980
aGuid(1) = &H101ABF32
aGuid(2) = &HAA00BB8B
aGuid(3) = &HAB0C3000
OleCreatePictureIndirect lpPictDesc, aGuid(0), True, NewIco
Set Pic = NewIco
SaveName = "D:\Icons\" & i & ".ico"
SavePicture Pic, SaveName
End If
Next
End Sub
但是,还有一点儿遗憾,看你能否发现?
板凳
我是大喊三 [专家分:3010] 发布于 2008-09-10 18:57:00
我发现我对LZ的问题有阅读障碍
3 楼
yujimin [专家分:0] 发布于 2008-09-11 11:15:00
回一楼的!
保存后的图标变样了啊,颜色不对。
能不能不先建文件夹呢?
我上传图片了啊,怎么看不到图片呢?图片要如何上传呢?
4 楼
wwc7654321 [专家分:1590] 发布于 2008-09-13 22:30:00
不先建文件夹
OpenName = "%SystemRoot%\system32\SHELL32.dll" '这个文件中有237个图标
前加上
If Len(Dir("D:\Icons", vbDirectory)) = 0 Then MkDir "D:\Icons"
好像是savepicture的问题吧,明明显示出来是32色的,一保存就变16色了
5 楼
yujimin [专家分:0] 发布于 2008-09-18 10:55:00
[quote]楼主想得轻松,想得美,呵呵。。。
不过,幸好碰到了我,我的一个爱好就是成人之美。
先在你的 D 盘上新建一个 Icons 文件夹。
代码如下:
Option Explicit
Private Type PICTDESC
Size As Long
Type As Long
hBmpOrIcon As Long
hPal As Long
End Type
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PICTDESC, riid As Any, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Sub Command1_Click()
Dim i As Integer, IconCount As Integer, ihdc As Long, aGuid(0 To 3) As Long
Dim OpenName As String, SaveName As String
Dim lpPictDesc As PICTDESC, NewIco As IPicture, Pic As StdPicture
OpenName = "%SystemRoot%\system32\SHELL32.dll" '这个文件中有237个图标
IconCount = ExtractIcon(0, OpenName, -1)
If IconCount = 0 Then MsgBox "该文件不含图标": Exit Sub
For i = 1 To IconCount
ihdc = ExtractIcon(0, OpenName, i)
If ihdc Then
lpPictDesc.Size = Len(lpPictDesc)
lpPictDesc.Type = vbPicTypeIcon
lpPictDesc.hBmpOrIcon = ihdc
aGuid(0) = &H7BF80980
aGuid(1) = &H101ABF32
aGuid(2) = &HAA00BB8B
aGuid(3) = &HAB0C3000
OleCreatePictureIndirect lpPictDesc, aGuid(0), True, NewIco
Set Pic = NewIco
SaveName = "D:\Icons\" & i & ".ico"
SavePicture Pic, SaveName
End If
Next
End Sub
但是,还有一点儿遗憾,看你能否发现?[/quote]
提取的图标不是32色的啊?
6 楼
一江秋水 [专家分:9680] 发布于 2008-09-18 11:58:00
这就是我所说的遗憾。真彩变成了16色,可能是没有引入系统调色板,我正在做试验,目前暂无进展。。。
7 楼
yujimin [专家分:0] 发布于 2008-09-21 14:13:00
[quote]这就是我所说的遗憾。真彩变成了16色,可能是没有引入系统调色板,我正在做试验,目前暂无进展。。。[/quote]
我试了很多代码都不能保存真色彩的图标,保存的都是16色的。
等您的消息!
PS:我有个这样的小软件,不过不知道怎么上传!这个软件是可以提取并保存真色彩图标的。只是没有源代码。截图也不能上传!
8 楼
hongrenguo [专家分:10] 发布于 2008-10-12 20:16:00
我有个软件好像可以实现,是用VB编写的,下次回家我把源代码发上来。
9 楼
yujimin [专家分:0] 发布于 2008-10-16 07:19:00
[quote]我有个软件好像可以实现,是用VB编写的,下次回家我把源代码发上来。[/quote]
什么时间啊!快点啊!呵呵!
10 楼
tanchuhan [专家分:15140] 发布于 2008-10-16 22:35:00
要提取真菜色的图标,只能分析Icon文件和BMP文件的结构,然后自己用二进制写入。
我当年写过,不过是VC代码来的(现在已经找不着了),在MSDN里面找到的参考例子。
我来回复