没有人知道如何编程替换程序的图标吗?帮我看看这段程序。(25分)

  • 主题发起人 主题发起人 you_known
  • 开始时间 开始时间
Y

you_known

Unregistered / Unconfirmed
GUEST, unregistred user!
我在MSDN上找到有关资源替换的源代码,将它翻译成Delphi,但是无法成功。
不知道是哪里有问题?各位帮帮忙看看,谢谢了。
====Delphi============================================================
function MakeLangID(PrimaryLanguage,SubLanguage : word) : DWord;
begin
Result:=SubLanguage shl 10;
Result:=Result or PrimaryLanguage;
end;

procedure change;
var
hResLoad:HRSRC; // handle to loaded resource
hExe:THANDLE; // handle to existing .EXE file
hRes:HRSRC; // handle/ptr. to res. info. in hExe
hUpdateRes:THANDLE; // update resource handle
lpResLock:^char; // pointer to resource data
return:BOOL;
begin
hExe := LoadLibrary('D:/M.exe');
if hExe=0 then messagebox(0,'error open exe','error',0);

hRes := FindResource(hExe, 'MAINICON', RT_ICON);
if hRes=0 then messagebox(0,'can not find ico','error',0);

hResLoad:= LoadResource(hExe, hRes);
if hResLoad=0 then messagebox(0,'Load error','error',0);

lpResLock:= LockResource(hResLoad);
if lpReslock=nil then messagebox(0,'can not lock resource','error',0);

hUpdateRes:= BeginUpdateResource('d:/P.exe', FALSE);
if hUpdateRes=0 then messagebox(0,'can not open file for write','error',0);

return:= UpdateResource(hUpdateRes, // update resource handle
RT_ICON, // change Icon resource
'MAINICON', // Icon name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if return=false then messagebox(0,'can not add res','error',0);

if (not EndUpdateResource(hUpdateRes, FALSE)) then messagebox(0,'can not make change','error',0);

if (not FreeLibrary(hExe)) then messagebox(0,'can not free exe','error',0);
end;
======================================================================
下面是C的源代码:
====C/C++=============================================================
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.");
}

 
Why two paste?
>> http://www.delphibbs.com/delphibbs/dispq.asp?lid=719024
 
BeginUpdateResource win98好像不支持
 
你来封信,我给你发一个工具,很好用的。我在网上找的,没有源码。
b5790930@pub.xz.jsinfo.net
 
后退
顶部