能否用代码改变另一程序左上角的图标?(40分)

H

hying95

Unregistered / Unconfirmed
GUEST, unregistred user!
可以啊
很多 exe 左上角的图标 是 exe的图标
很容易 改啊
delphi自带的demo里就有啊
不过 delphi的 icon类 有缺陷 对 多尺寸 支持 有问题
你要注意
 
可以这样:
Application.Icon.LoadFromFile('c:/1.ico');
 
LS的两位没有仔细看问题吧?是改其他的程序图标,不是改自己的,所以绝非你们想的那么简单。不过LZ只出这点分就想解决问题?你出40英镑都不一定有人帮你搞定!祝你好运。
 
我说的 就是 改其他 程序 的
 
你先看 D:/Program Files/Borland/Delphi7/Demos/ResXplor
自带的 demo

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, shellapi, ExeImage, rxtypes;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
Button4: TButton;
Label1: TLabel;
procedure Button4Click(Sender: TObject);
private
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ChageExeIcon(IconFileName, EXEFileName: string);
var
NewIcon: TIcon;
NewSize: integer;
NewIcon_ms: TMemoryStream;
fn: string;
ResOffset,
ms_size: Longint;
t, t2: Longint;
Exe: TExeImage;
ms: TMemoryStream;
fs: TFileStream;
i: integer;
b: byte;
procedure LoadResources(ResList: TResourceList);
var
I: Integer;
begin
for I := 0 to ResList.Count - 1do
with ResListdo
begin
if IsList then
begin
if sametext('Icon', ResList.Name) or sametext('MAINICON',
ResList.Name) then
LoadResources(List);
end
else
begin

ms_size := ResList.Size + 22;
if NewSize = ms_size then
begin
ResOffset := ResList.Offset;
Break;
end;
end;

end;
end;

begin

NewIcon := TIcon.Create;
NewIcon_ms := TMemoryStream.Create;
try
NewIcon.LoadFromFile(IconFileName);
// NewIcon.Handle
NewIcon.SaveToStream(NewIcon_ms);
NewSize := NewIcon_ms.Size;
ms_size := 0;
exe := TExeImage.CreateImage(nil, EXEFileName);
try
LoadResources(exe.Resources);
T := Exe.ResSectHdr.PointerToRawData;
t2 := Exe.ResSectHdr.VirtualAddress;
finally
FreeAndNil(exe);
end;

if ms_size <> NewSize then
begin
showmessage('大小不一致!');
end
else
begin
fs := TFileStream.Create(EXEFileName, fmopenwrite);
try
fs.Position := ResOffset + t - t2;
NewIcon_ms.Position := 22;
for i := 1 to NewSize - 22do
begin
NewIcon_ms.Read(b, 1);
fs.Write(b, 1);
end;
except
;
end;
FreeAndNil(fs);
end;
except
end;
FreeAndNil(NewIcon_ms);
FreeAndNil(NewIcon);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
IconFileName, EXEFileName: string;
begin
if OpenDialog2.Execute then
begin
IconFileName := OpenDialog2.FileName;
end;
if OpenDialog1.Execute then
begin
EXEFileName := OpenDialog1.FileName;
end;
ChageExeIcon(IconFileName, EXEFileName);
end;

end.
 
一个ico文件可以包含多幅 图像
一个exe文件的图标 也是多个。
delphi 的TIcon有缺陷。
ChageExeIcon目前只支持
单帧 的ico文件
另外:
The ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.
HICON ExtractIcon(
HINSTANCE hInst, // instance handle
LPCTSTR lpszExeFileName, // filename of file with icon
UINT nIconIndex // index of icon to extract
);

Parameters
hInst
Identifies the instance of the application calling the function.
lpszExeFileName
Points to a null-terminated string specifying the name of an executable file, DLL, or icon file.
nIconIndex
Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file.
If this value is -1, the function returns the total number of icons in the specified file.
"value is -1" 但是 他可是 UINT类型的
复件 Project2.exe 就是修改过的多个图标的exe,在大图标和小图标 两种浏览方式 下 完全不一样
 
to hfghfhgfg
有两个地方编译通不过
try
LoadResources(exe.Resources);
T := Exe.ResSectHdr.PointerToRawData;//这里编译通不过
t2 := Exe.ResSectHdr.VirtualAddress;//这里编译通不过
finally
FreeAndNil(exe);
end;
 
顶部