H
hlsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用下面的方法提取dll中的图标:
image1.picture.icon.Handle:=ExtractIcon(hInstance,'c:/windows/system/shell32.dll',4);
image1.picture.icon.savetofile('C:/1.ico');
可原本是256色的图标变成了16色,怎么才能使保存出来的ICO使用原来的颜色数呢?
我是初学者,请各位高手帮忙。谢谢。
你只要解决了这个问题,除了本题的300分,还有许多相同问题的分都是你的啦!
LID
593378 200分
507223 100分
下面是电脑爱好者上的一篇文章,也许对大家有点帮助。
用VB6制作图标提取器
--------------------- 1 ------------------------
Dim ICONSS, tt, JISHU
DIM fNAME As String
Private Sub Command1_Click()
'本按钮用来选定二进制文件
'并且调用图标个数判断和提取过程
Co1.FileName = ""
Co1.Filter = "二进制文件|*.exe;*.dll;*.ocx"
Co1.ShowOpen
If Co1.FileName = "" Then Exit Sub
fNAME = Co1.FileName'向图标提取过程传递被提取文件名参数
Lis fNAME ’图标个数判断和提取
End Sub
Private Sub Command2_Click()
'本过程生成并且保存图标文件
With Co1
.FileName = ""
.Filter = "图标文件(*.ico)|*.ico"
.ShowSave
End With
If Co1.FileName = "" Then
Exit Sub
End If
SavePicture Pic1.Picture, Co1.FileName
'利用SavePicture保存图标
End Sub
Private Sub Command3_Click()
'本按钮控制软件的退出
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
End '退出程序
End Sub
Private Sub Lis(fNAME As String)
'本过程用来判断选定文件所含图标个数
'它需要一个文件名作为参数
'并且生成第一个图标
Dim I As Integer, I1 As Integer, I2 As Integer
ICONSS = ExtractIcon(1, fNAME, -1)
Check1.Caption = "选定文件(" & fNAME + ")含图标:" & ICONSS & "个"
'显示图标个数
If ICONSS < 1 Then
'如果没有图标那么退出函数
Command2.Enabled = False
Exit Sub
Else
With HS
Command2.Enabled = True
If ICONSS = 1 Then
'如果只有一个图标
.Min = 1
.Max = 1
.Value = 1
Else
'如果多于一个图标
.Min = 1
.Max = ICONSS
.Value = 1
End If
fenli fNAME, 0
'调用图标创建函数
End With
End If
End Sub
Private Sub Form_Load()
Me.Caption = App.Title & "为《电脑爱好者投稿》 版本 " & App.Major _
& "." & App.Minor & "." & App.Revision
'添加应用程序标题和版本号
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
'窗体位置居中
Check1.Caption = "!请通过浏览选择一个可执行文件或者动态链接库文件!"
Command2.Enabled = False
End Sub
Private Sub fenli(allfname As String, va As Integer)
'图标创建过程
Dim myicon As Long
Dim Y As Long
Dim oopp As IPictureDisp
Dim dddd As ICONINFO
myicon = ExtractIcon(0, allfname, va)
'读出一个图标
GetIconInfo myicon, dddd
'获得图标信息
Y = CreateIconIndirect(dddd)
Set oopp = IconToPicture(Y)
'重新创建一个图标
Pic1.Picture = oopp
'将创建完成后的图标显示到pic1
End Sub
Private Sub HS_Change()
'浏览其他的图标
fenli fNAME, HS.Value - 1
End Sub
--------------------- 2 ------------------------
Option Explicit
Public Type ICONINFO
fIcon As Long
xHotspot As Long
yHotspot As Long
hbmMask As Long
hbmColor As Long
End Type '图标信息类型定义
Public Type TypeIcon
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type
Public Type CLSID
ID(16) As Byte
End Type '图标创建id
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long '判断一个可执行文件或DLL中是否有图标存在,并将其提取出来,nIconIndex返回lpszExeFileName指定文件图标的个数'hinst=1表示需要返回的个数
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long) As Long '在指定的位置画一个图标
Public Declare Function CreateIconIndirect Lib "user32" (piconinfo As ICONINFO) As Long
'创建一个766字节的windows标准图标
Public Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As TypeIcon, riid As CLSID, ByVal fown As Long, lpUnk As Object) As Long'生成图标
Public Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long '取得与图标有关的信息
Public Function IconToPicture(hIcon As Long) As IPictureDisp
'图标文件生成过程
Dim ID As CLSID
Dim hR As Long
Dim Nicon As TypeIcon
Dim LP As IUnknown
With Nicon
.cbSize = Len(Nicon)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With
With ID
.ID(8) = 192
.ID(15) = 70
End With
'以上参数是必须的,它表示将要从内存中创建图标
hR = OleCreatePictureIndirect(Nicon, ID, 1, LP)
'完成创建,hr=0表示创建失败
If hR = 0 Then
Set IconToPicture = LP
Else
MsgBox "提取出错!文件内部图标已经不可用!", vbOKOnly + vbExclamation
End If
End Function'结束
下面是对上篇文章的补充。
升级“图标提取器”
Private Sub fenli(allfname As String, va As Integer)
'图标创建过程
Dim myicon As Long
myicon = ExtractIcon(0, allfname, va) '读出一个图标
pic1.Picture = IconToPicture(myicon) '将创建完成后的图标显示到pic1
End Sub
--------------------------------------------------------------------------
Public Function IconToPicture(hIcon As Long) As IPictureDisp
Dim ID As CLSID
Dim hR As Long
Dim Nicon As TypeIcon
Dim LP As IUnknown
With Nicon
.cbSize = Len(Nicon)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With
With ID
.ID(8) = 192
.ID(15) = 70
End With
hR = OleCreatePictureIndirect(Nicon, ID, 1, LP)
DestroyIcon hIcon '释放图标占用的内存及资源
If hR = 0 Then
Set IconToPicture = LP
Else
MsgBox "提取出错!文件内部图标已经不可用!", vbOKOnly + vbExclamation
End If
End Function
image1.picture.icon.Handle:=ExtractIcon(hInstance,'c:/windows/system/shell32.dll',4);
image1.picture.icon.savetofile('C:/1.ico');
可原本是256色的图标变成了16色,怎么才能使保存出来的ICO使用原来的颜色数呢?
我是初学者,请各位高手帮忙。谢谢。
你只要解决了这个问题,除了本题的300分,还有许多相同问题的分都是你的啦!
LID
593378 200分
507223 100分
下面是电脑爱好者上的一篇文章,也许对大家有点帮助。
用VB6制作图标提取器
--------------------- 1 ------------------------
Dim ICONSS, tt, JISHU
DIM fNAME As String
Private Sub Command1_Click()
'本按钮用来选定二进制文件
'并且调用图标个数判断和提取过程
Co1.FileName = ""
Co1.Filter = "二进制文件|*.exe;*.dll;*.ocx"
Co1.ShowOpen
If Co1.FileName = "" Then Exit Sub
fNAME = Co1.FileName'向图标提取过程传递被提取文件名参数
Lis fNAME ’图标个数判断和提取
End Sub
Private Sub Command2_Click()
'本过程生成并且保存图标文件
With Co1
.FileName = ""
.Filter = "图标文件(*.ico)|*.ico"
.ShowSave
End With
If Co1.FileName = "" Then
Exit Sub
End If
SavePicture Pic1.Picture, Co1.FileName
'利用SavePicture保存图标
End Sub
Private Sub Command3_Click()
'本按钮控制软件的退出
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
End '退出程序
End Sub
Private Sub Lis(fNAME As String)
'本过程用来判断选定文件所含图标个数
'它需要一个文件名作为参数
'并且生成第一个图标
Dim I As Integer, I1 As Integer, I2 As Integer
ICONSS = ExtractIcon(1, fNAME, -1)
Check1.Caption = "选定文件(" & fNAME + ")含图标:" & ICONSS & "个"
'显示图标个数
If ICONSS < 1 Then
'如果没有图标那么退出函数
Command2.Enabled = False
Exit Sub
Else
With HS
Command2.Enabled = True
If ICONSS = 1 Then
'如果只有一个图标
.Min = 1
.Max = 1
.Value = 1
Else
'如果多于一个图标
.Min = 1
.Max = ICONSS
.Value = 1
End If
fenli fNAME, 0
'调用图标创建函数
End With
End If
End Sub
Private Sub Form_Load()
Me.Caption = App.Title & "为《电脑爱好者投稿》 版本 " & App.Major _
& "." & App.Minor & "." & App.Revision
'添加应用程序标题和版本号
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
'窗体位置居中
Check1.Caption = "!请通过浏览选择一个可执行文件或者动态链接库文件!"
Command2.Enabled = False
End Sub
Private Sub fenli(allfname As String, va As Integer)
'图标创建过程
Dim myicon As Long
Dim Y As Long
Dim oopp As IPictureDisp
Dim dddd As ICONINFO
myicon = ExtractIcon(0, allfname, va)
'读出一个图标
GetIconInfo myicon, dddd
'获得图标信息
Y = CreateIconIndirect(dddd)
Set oopp = IconToPicture(Y)
'重新创建一个图标
Pic1.Picture = oopp
'将创建完成后的图标显示到pic1
End Sub
Private Sub HS_Change()
'浏览其他的图标
fenli fNAME, HS.Value - 1
End Sub
--------------------- 2 ------------------------
Option Explicit
Public Type ICONINFO
fIcon As Long
xHotspot As Long
yHotspot As Long
hbmMask As Long
hbmColor As Long
End Type '图标信息类型定义
Public Type TypeIcon
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type
Public Type CLSID
ID(16) As Byte
End Type '图标创建id
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long '判断一个可执行文件或DLL中是否有图标存在,并将其提取出来,nIconIndex返回lpszExeFileName指定文件图标的个数'hinst=1表示需要返回的个数
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long) As Long '在指定的位置画一个图标
Public Declare Function CreateIconIndirect Lib "user32" (piconinfo As ICONINFO) As Long
'创建一个766字节的windows标准图标
Public Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As TypeIcon, riid As CLSID, ByVal fown As Long, lpUnk As Object) As Long'生成图标
Public Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long '取得与图标有关的信息
Public Function IconToPicture(hIcon As Long) As IPictureDisp
'图标文件生成过程
Dim ID As CLSID
Dim hR As Long
Dim Nicon As TypeIcon
Dim LP As IUnknown
With Nicon
.cbSize = Len(Nicon)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With
With ID
.ID(8) = 192
.ID(15) = 70
End With
'以上参数是必须的,它表示将要从内存中创建图标
hR = OleCreatePictureIndirect(Nicon, ID, 1, LP)
'完成创建,hr=0表示创建失败
If hR = 0 Then
Set IconToPicture = LP
Else
MsgBox "提取出错!文件内部图标已经不可用!", vbOKOnly + vbExclamation
End If
End Function'结束
下面是对上篇文章的补充。
升级“图标提取器”
Private Sub fenli(allfname As String, va As Integer)
'图标创建过程
Dim myicon As Long
myicon = ExtractIcon(0, allfname, va) '读出一个图标
pic1.Picture = IconToPicture(myicon) '将创建完成后的图标显示到pic1
End Sub
--------------------------------------------------------------------------
Public Function IconToPicture(hIcon As Long) As IPictureDisp
Dim ID As CLSID
Dim hR As Long
Dim Nicon As TypeIcon
Dim LP As IUnknown
With Nicon
.cbSize = Len(Nicon)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With
With ID
.ID(8) = 192
.ID(15) = 70
End With
hR = OleCreatePictureIndirect(Nicon, ID, 1, LP)
DestroyIcon hIcon '释放图标占用的内存及资源
If hR = 0 Then
Set IconToPicture = LP
Else
MsgBox "提取出错!文件内部图标已经不可用!", vbOKOnly + vbExclamation
End If
End Function