如何制作EXE文件图标

如何制作EXE文件图标,第1张

可以用一些在线的工具来制作比较方便快捷,比如这个在线的图标制作工具,就可以很轻松制作了,他可以选择不同的图标尺寸,以及不同用途的图标的类型,还能选择输出不同的图标格式,挺方便可以尝试。在线ICO图标制作生成,图片转换ICO图标

图片转换ICO图标Pro版步骤

一、点击或者拖拽到上传框中,即可上传你要转换的图片,直接将新图片拖入上传框即可更换图片。目前已知支持jpg、png等多种常见的图片格式,如果上传图片并转换ico图标成功,则代表支持该格式。

二、此时预览框中会出现刚刚上传的图片,可以任意缩放拖拽裁剪框,选择你想要截取并转换ico图标的区域。在拖拽缩放裁剪框的过程中,左上方会有ico图标效果的实时预览。

三、选择需要生成的ico图标的尺寸,主要提供宽高为16、32、48、64、128、256、512的尺寸以供选择。通常的ico图标基本都是32、64或者128像素的。

四、选择生成的ICO图标的类型,默认为普通网站ICO图标,也就是可以在web应用中使用的ICO图标;也可以选择Windows系统桌面标准格式ICO图标类型,这种类型的ICO图标可以作为Windows桌面图标等。

五、选择生成的ICO图标的编码格式,默认为不透明背景,适用于非镂空图片生成ico,这种格式的ICO文件最小;透明背景的ICO图标,指的是将原本存在透明背景的图片生成背景透明的ICO图标,文件较大。

六、选择转换生成的ico图标的文件格式,默认的格式是.ico,并且有.jpg和.png格式可以选择。需要注意的是,ico图标一般都是背景镂空透明的图形,只有.ico和.png格式支持透明背景的图片,而.jpg格式的图片本身是不支持的。

下面是修改一个图标的方法:

分二步:

一、把下面代码复制到一个模块中:

Option Explicit

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long

Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long

Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long

Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, ByVal lpType As Long, ByVal lpName As Long, ByVal wLanguage As Long, lpData As Any, ByVal cbData As Long) As Long

Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function GetLastError Lib "kernel32" () As Long

Private Const INVALID_HANDLE_VALUE = -1

Private Const GENERIC_READ = &H80000000

Private Const FILE_ATTRIBUTE_NORMAL = &H80

Private Const FILE_BEGIN = 0

Private Const OPEN_EXISTING = 3

Private Const RT_ICON = 3&

Private Const DIFFERENCE As Long = 11

Private Const RT_GROUP_ICON As Long = (RT_ICON + DIFFERENCE)

Private Type ICONDIRENTRY

bWidth As Byte

bHeight As Byte

bColorCount As Byte

bReserved As Byte

wPlanes As Integer

wBitCount As Integer

dwBytesInRes As Long

dwImageOffset As Long

End Type

Private Type ICONDIR

idReserved As Integer

idType As Integer

idCount As Integer

'idEntries As ICONDIRENTRY

End Type

Private Type GRPICONDIRENTRY

bWidth As Byte

bHeight As Byte

bColorCount As Byte

bReserved As Byte

wPlanes As Integer

wBitCount As Integer

dwBytesInRes As Long

nID As Integer

End Type

Private Type GRPICONDIR

idReserved As Integer

idType As Integer

idCount As Integer

idEntries As GRPICONDIRENTRY

End Type

'//////////////////////////////////////////////

'//函数说明:修改EXE图标

'//

'//参数:IconFile 图标文件

'//ExeFile 被修改的EXE文件

'//

'//返回值: 成功为True,否则False

'/////////////////////////////////////////////////////

Private Function ChangeExeIcon(ByVal IconFile As String, ByVal ExeFile As String) As Boolean

On Error GoTo cw

Dim stID As ICONDIR

Dim stIDE As ICONDIRENTRY

Dim stGID As GRPICONDIR

Dim hFile As Long

Dim pIcon() As Byte, pGrpIcon() As Byte

Dim nSize As Long, nGSize As Long

Dim dwReserved As Long

Dim hUpdate As Long

Dim ret As Long

hFile = CreateFile(IconFile, GENERIC_READ, 0, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)

If hFile = INVALID_HANDLE_VALUE Then Exit Function

ret = ReadFile(hFile, stID, Len(stID), dwReserved, ByVal 0&)

If ret = 0 Then GoTo cw

ret = ReadFile(hFile, stIDE, Len(stIDE), dwReserved, ByVal 0&)

nSize = stIDE.dwBytesInRes

ReDim pIcon(nSize - 1)

SetFilePointer hFile, stIDE.dwImageOffset, ByVal 0&, FILE_BEGIN

ret = ReadFile(hFile, pIcon(0), nSize, dwReserved, ByVal 0&)

If ret = 0 Then GoTo cw

With stGID

.idType = 1

.idCount = stID.idCount

.idReserved = 0

CopyMemory stGID.idEntries, stIDE, 12

.idEntries.nID = 0

End With

nGSize = Len(stGID)

ReDim pGrpIcon(nGSize - 1)

CopyMemory pGrpIcon(0), stGID, nGSize

hUpdate = BeginUpdateResource(ExeFile, False)

ret = UpdateResource(hUpdate, RT_GROUP_ICON, 1, 0, pGrpIcon(0), nGSize)

ret = UpdateResource(hUpdate, RT_ICON, 1, 0, pIcon(0), nSize)

EndUpdateResource hUpdate, False

If ret = 0 Then GoTo cw

ChangeExeIcon = True

cw:

CloseHandle hFile

End Function

二、程序调用:

if ChangeExeIcon("D:\B.ICO","D:\A.EXE") then

msgbox "替换成功!"

else

msgbox "替换失败!"

endif

下面是找出一个盘里面所有exe文件的方法:

使用filelistbox,dirlistbox,drivelistbox三个控件连用就可以做到,把他们当做listbox读出列表中的所有list然后循环搜索,就可以找出你要的exe文件了。

Dir1.Path = Drive1.list(i)'连接dirlistbox,drivelistbox,在form_load里面

File1.Path = Dir1.list(i)'连接filelistbox,dirlistbox,在form_load里面

File1.Refresh '刷新file

File1.Pattern="*.exe"'指定文件格式

然后转存file1.list(i)就可以了

以上i表示循环控制变量

ico做图标有两种方法:

1、静态图标,即在vb窗体的icon属性中指定一个图标,此时图标是以资源文件的方式保存在.frx文件中。编译时,该图标会添加到编译后的.exe文件中。

2、动态图标,在程序中通过代码方式实现图标的加载,例如:

Form1.Icon = LoadPicture("c:\myicon.ico")

编译后,该图标不会添加到.exe文件中,但运行该程序时,指定的路径下若无该图标文件,程序会报53号错误。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12196667.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存