一个超出了水平的问题!!!(50分)

F

favinc

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用程序的方法更改另外一个可执行程序的图标?
 
只要能够分析PE文件格式, 然后从程序中找到图标资源的定位点, 再从图标文件中读
出想要的图标, 再从定位点开始写入覆盖原来的文件中的图标就可以了.
图标有一点好的, 就是所占空间大小是固定的(相同尺寸和颜色数).
 
方法我知道,我能获得图标的RVA,但无法获取它们正确的物理地址;
 
LoadBitmap()函数不太好用,用于资源文件的使用中!!!!
 
提取他得图标倒是很简单啊
 
如果搞定了请说一声,谢谢:)lovejingtao@21cn.com
我有一个,但效率奇低。。。。。
 
favinc兄:你不肯回答就算了,早晚我搞定它:)
 
搞定了告诉我一声呀
大家共同进步呀
 
我也想知道
 
很简单,今天太晚了,上班再说
 

用改资源的软件,就是作汉化的那些就可以。
 
可以看到效果,但不能永久改变
function FindWindowLike(Level:integer;hWndStart:HWND;WindowText:string;WindowClass:string):HWND;
var
hwndLike:HWND;
WndCaption:array[0..254] of char;
WndClassName:array[0..254] of char;
begin
if level=0 then
if hWndStart=0 then
hWndStart:=GetDesktopWindow;
level:=level+1;
hwndLike:=GetWindow(hWndStart,GW_CHILD);
while hwndLike<>0do
begin
FindWindowLike(level,hwndLike,WindowText,WindowClass);
GetWindowText(hwndLike,@WndCaption,254);
GetClassName(hwndLike,@WndClassName,254);
if pos(WindowText,StrPas(WndCaption))<>0 then
begin
if ((pos(WindowClass,StrPas(WndClassName))<>0) or (WindowClass='')) then
begin
form1.Memo1.Lines.Add(StrPas(WndCaption));
form1.Memo1.Lines.Add(StrPas(WndClassName));
form1.Memo1.Lines.Add(inttostr(hwndlike));
form1.Memo1.Lines.Add(StrPas('------------'));
FindWindowLike:=hwndLike;
end;
//end if 找到匹配窗口名称与类名或窗口名称匹配
end;

hwndLike:=GetWindow(hwndLike,GW_HWNDNEXT);
end;
level:=level-1;
end;

//可以找到应用程序的句柄
procedure TForm1.Button1Click(Sender: TObject);
begin
FindWindowLike(0,0,Edit1.Text,'');
//第3个参数是应用程序的标题
//第4个参数是应用程序的类名,可以为空如上,也可以输入类名用来准却查找如下
//FindWindowLike(0,0,Edit1.Text,Edit2.Text);
end;
//根据应用程序的句柄,更改图标
procedure TForm1.Button2Click(Sender: TObject);
var
S: String;
wnd: HWND;
begin
//通过button1可以找到应用程序的句柄,输入到edit1
wnd:=strtoint(Edit1.Text);
s:=edit1.text;
SendMessage(wnd, WM_SETICON, ICON_SMALL, Application.Icon.Handle);
//改图标
SetWindowText(Wnd, Pchar(S));
//改标题
end;
 
早就搞定了,谢谢。
 
很好做,临时给你写了个函数,拿去用吧,nt/2000/xp下才能用,如果在9x下用,需要客户
安装额外的包,我忘了叫什么了,呵呵
type
icondir = packed record
reserved: word;
ictype: word;
count: word;
width: byte;
height: byte;
colorcount: byte;
reserve: byte;
schema: word;
bitcount: word;
bytesinres: dword;
imageoffset: dword;
end;

function puticon(exe, ico: string;
resid, lang: integer): boolean;
var icon: thandle;
hexe: thandle;
buffer: pointer;
size, read: dword;
idir: icondir;
begin
result := true;
icon := createfile(pchar(ico), generic_read, file_share_read, nil, Open_existing, file_attribute_normal, 0);
if icon = 0 then
result := false;
if not ReadFile(icon, idir, sizeof(idir), read, nil) then
result := false;
size := idir.bytesinres;
getmem(buffer, size);
SetFilePointer(icon, idir.imageoffset, NiL, FILE_begin
);
if not ReadFile(icon, buffer^, size, read, nil) then
result := false;
closehandle(icon);
hEXE := begin
UpdateResource(pchar(exe), false);
if hEXE<>0 then
begin
if not UpdateResource(hEXE, RT_ICON, MAKEINTRESOURCE(resid), lang, buffer, read) then
result := false;
if not EndUpdateResource(hEXE, false) then
result := false;
end;
freemem(buffer);
end;
注意,要换图标,你必须先用enum出资源,然后把里面的图标替换掉,有一个资源专门指定那个
图标作为exe的图标,替换掉就成了
 
btw,我的方法是永久的,呵呵
 
这里有一个程序源代码,里面有教你做。
http://delphi.mychangshu.com/downfile.asp?ID=293&amp;location=icotools.zip
 
顶部