这里高手如云,我就不相信解决不了我这设置文件图标的问题!

pms 2001-04-12 12:26:00
已经用ExtractIcon函数获得file1.exe的图标,如何将file2.exe的图标设为file1.exe的图标?最好要有代码示例。难道这个问题会这么难?!我问遍了各个论坛都没人能真正回答!我最高只能给57分了(但我可用分有783分啊,怎么回事?)。
...全文
537 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
pms 2001-04-15
  • 打赏
  • 举报
回复
看来真的没人懂,我只好挪一个地方了。
pms 2001-04-14
  • 打赏
  • 举报
回复
但我知道这是可以实现的,因为我用过一个给可执行文件加密码的程序,还有一个绑定两个可执行文件的程序,它们应该都是给可执行程序加一层外壳吧?但它们都能保证目标文件和源文件的图标一样。
pms 2001-04-14
  • 打赏
  • 举报
回复
真的没人知道吗?
lgs 2001-04-13
  • 打赏
  • 举报
回复
Win9x下是不能用的。
ytdxl 2001-04-13
  • 打赏
  • 举报
回复
关注
孩皮妞野 2001-04-12
  • 打赏
  • 举报
回复
>>Holyfire
这个函数是修改了.exe还是修改了内存中的映象?
孩皮妞野 2001-04-12
  • 打赏
  • 举报
回复
解决了,快给分给Holyfire大虾吧!

我记下来先!
holyfire 2001-04-12
  • 打赏
  • 举报
回复
呵呵,提供C/E两个版本。

BeginUpdateResource

函数功能:该函数返回一个可被UpdateResource函数使用的句柄以便在一个可执行文件中增加、删除或替换资源。

函数原型:HANDLE BeginUpdateResource(LPCTSTR pFileName,BOOL bDeleteExistingResources);

参数:

pFileName:指向一个表示结束的空字符串指针,它是用来指定用以更新资源的基于32-位可执行文件的文件名。应用程序必须获得访问这个文件的可写权限,并且此文件在当前状态下不能被执行。如果pFileName未被指定完全路径,系统将在当前路径下搜寻此文件。

bDeleteExistingResources:说明是否删除PFileName参数指定的现有资源。如果这个参数为TRUE则现有的资源将被删除,而更新可执行文件只包括由UpdateResource函数增加的资源。如果这个参数为FALSE,则更新的可执行文件包括现有的全部资源,除非通过UpdateResource特别说明被删除或是替换的。

UpdateResource
函数功能:该函数增加,删除,或替代某可执行文件中的资源。

函数原型:BOOL UPdateResource(HANDLE hUpdate,LPCTSTR lPTyPe,LPCTSTR IPName,WORD wLanguage,LPVOID lgData,DWORD cbData);

参数:

hUpdate:指定更新文件句柄。此句柄由BeginUpdateResource函数返回。

lpType:指向说明将被更新的资源类型的字符串,它以NULL为终止符。这个参数可以是一个通过宏MAKENTRESOURCE传递的整数值,含义参见EnumResLangProc\lpType。

lpName:指向说明待被更新的资源名称的字符串,它以NULL为终止符。这个参数可以是一个通过宏MAKEINTRESOURCE传递的整数值。

wLanguage:指定将被更新资源的语言标识。要了解基本的语言标识符以及由这些标识符组成的字语言标识符的列表,可参见宏MAKELANGID。

lpData:指向被插入可执行文件的资源数据的指针。如果资源是预定义类型值之一,那么数据必须是有效且适当排列的。注意这是存储在可执行文件中原始的一进制数据,而不是由Loadlcon,LoadString或其他装载特殊资源函数提供的数据。所有包含字符串、文本的数据必须是Unicode格式;IpData不能指向ANSI数据。

如果lpData为NULL,所指定的资源将从可执行文件中被删除。

cbData:指定lpData中的资源数据数据大小,以字节计数。
holyfire 2001-04-12
  • 打赏
  • 举报
回复
HANDLE BeginUpdateResource(
LPCTSTR pFileName, // executable file name
BOOL bDeleteExistingResources // deletion option
);

Parameters
pFileName
[in] Pointer to a null-terminated string that specifies the executable file in which to update resources. An application must be able to obtain write access to this file; it cannot be currently executing. If pFileName does not specify a full path, the system searches for the file in the current directory.
bDeleteExistingResources
[in] Specifies whether to delete the pFileName parameter's existing resources. If this parameter is TRUE, existing resources are deleted and the updated executable file includes only resources added with the UpdateResource function. If this parameter is FALSE, the updated executable file includes existing resources unless they are explicitly deleted or replaced by using UpdateResource.

BOOL UpdateResource(
HANDLE hUpdate, // update-file handle
LPCTSTR lpType, // resource type
LPCTSTR lpName, // resource name
WORD wLanguage, // language identifier
LPVOID lpData, // resource data
DWORD cbData // length of resource data
);
Parameters
hUpdate
[in] Specifies an update-file handle. This handle is returned by the BeginUpdateResource function.
lpType
[in] Pointer to a null-terminated string specifying the resource type to be updated. This parameter can also be an integer value passed to the MAKEINTRESOURCE macro, or it can be one of the following predefined resource types. Value Meaning
RT_ACCELERATOR Accelerator table
RT_ANICURSOR Animated cursor
RT_ANIICON Animated icon
RT_BITMAP Bitmap resource
RT_CURSOR Hardware-dependent cursor resource
RT_DIALOG Dialog box
RT_FONT Font resource
RT_FONTDIR Font directory resource
RT_GROUP_CURSOR Hardware-independent cursor resource
RT_GROUP_ICON Hardware-independent icon resource
RT_ICON Hardware-dependent icon resource
RT_MENU Menu resource
RT_MESSAGETABLE Message-table entry
RT_RCDATA Application-defined resource (raw data)
RT_STRING String-table entry
RT_VERSION Version resource


lpName
[in] Pointer to a null-terminated string specifying the name of the resource to be updated. This parameter can also be an integer value passed to the MAKEINTRESOURCE macro.
wLanguage
[in] Specifies the language identifier of the resource to be updated. For a list of the primary language identifiers and sublanguage identifiers that make up a language identifier, see the MAKELANGID macro.
lpData
[in] Pointer to the resource data to be inserted into the executable file. If the resource is one of the predefined types, the data must be valid and properly aligned. Note that this is the raw binary data stored in the executable file, not the data provided by LoadIcon, LoadString, or other resource-specific load functions. All data containing strings or text must be in Unicode format; lpData must not point to ANSI data.
If lpData is NULL, the specified resource is deleted from the executable file.

cbData
[in] Specifies the size, in bytes, of the resource data at lpData
孩皮妞野 2001-04-12
  • 打赏
  • 举报
回复
秋枫,难道图标在.exe中会以加密方式或分割开保存吗?我不知道具体情况,但我想如果微软决定这样毫无益处。我想图标时在可执行映象的某一位置连续保存的,现在的问题是确认这一假定,并找出这一位置。
chxr 2001-04-12
  • 打赏
  • 举报
回复
恩。是不是要用到SHELL编程。小弟对此类问题也非常感兴趣。
「已注销」 2001-04-12
  • 打赏
  • 举报
回复
修改资源不是那么容易的事情

关注此问题的解决
Sachow 2001-04-12
  • 打赏
  • 举报
回复
把file2.exe的图标设为file1.exe的图标,是要动态调用还是静态编入?
孩皮妞野 2001-04-12
  • 打赏
  • 举报
回复
这个恐怕跟ExtractIcon没有关系。关键要知道程序图标在.EXE中的位置,如果用等大的选定图标盖在.Exe中原来的位置,一定可以。你需要知道的是 把.exe 作为 一个二进制数据文件以可写方式打开后,图标的offset.

关于PE, NE的格式说明中可能会有着方面的说明。
holyfire 2001-04-12
  • 打赏
  • 举报
回复
我看了很多资料,只有如何读的,却没有写的,这个问题我也很想解决。
看来老外总是对我们留一手。
pms 2001-04-12
  • 打赏
  • 举报
回复
其实我的本意是这样的,给file2.exe加一层外壳,这层外壳其实就是file1.exe,结果加了外壳后的file2.exe的图标就变为file1.exe的图标,我现在的目的是仍然把file2.exe的图标还原回原有的,这真的很难?
孩皮妞野 2001-04-12
  • 打赏
  • 举报
回复
谢谢,我要开个贴子给老火加分了。
pms 2001-04-12
  • 打赏
  • 举报
回复
谢谢众神之焰,不过我主要用在win9x中怎么办?用execope等修改可能可以,但是我要应用在程序中啊,能否再帮助想办法?
holyfire 2001-04-12
  • 打赏
  • 举报
回复
在Win9x下没有相应的函数,不过应该有办法,execope和workshop都能做到,不过现在没资料。
holyfire 2001-04-12
  • 打赏
  • 举报
回复
HRSRC hResLoad; // handle to loaded resource
HANDLE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
ErrorHandler("Could not load exe.");
}

// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
ErrorHandler("Could not locate dialog box.");
}

// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
ErrorHandler("Could not load dialog box.");
}

// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
ErrorHandler("Could not lock dialog box.");
}

// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("foot.exe", FALSE);
if (hUpdateRes == NULL)
{
ErrorHandler("Could not open file for writing.");
}

// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes, // update resource handle
RT_DIALOG, // change dialog box resource
"AboutBox", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
ErrorHandler("Could not add resource.");
}

// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
ErrorHandler("Could not write changes to file.");
}

// Clean up.
if (!FreeLibrary(hExe))
{
ErrorHandler("Could not free executable.");
}
加载更多回复(2)

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧