L
lfpsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
在以下代码中.如果在"更换图标"对话框中没有使用"浏览"按扭选择其他文件,则取得的
EXE或DLL文件中的图标是正确的,但如果使用了,那么得到的图标就不是想得到的那个了.
请问这个问题可以解决吗?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Function SHChangeIconDialog(hOwner:hwnd;szFilenamewideChar;Reserved:longint; var lpIconIndex:Longint):Longint;stdcall;external 'shell32' index 62;
{$R *.dfm}
function GetIconFromExe(ExeName:String):HIcon;
Var ic:longint;
idx:longint;
Exewidechar;
begin
getmem(Exe,255);
stringtowidechar(ExeName,Exe,255);
ic:=SHChangeIconDialog(form1.handle,Exe,0,idx);//调用图标更换对话框
if ic<>0 then //成功调用
result:=extracticon(0,pchar(widechartostring(Exe)),idx);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Filter := '图标库(*.ico;*.exe;*.dll;*.icl)|*.ico;*.exe;*.dll;*.icl';
if OpenDialog1.Execute then
Image1.Picture.Icon.Handle := GetIconFromExe(Opendialog1.fileName);
end;
end.
EXE或DLL文件中的图标是正确的,但如果使用了,那么得到的图标就不是想得到的那个了.
请问这个问题可以解决吗?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Function SHChangeIconDialog(hOwner:hwnd;szFilenamewideChar;Reserved:longint; var lpIconIndex:Longint):Longint;stdcall;external 'shell32' index 62;
{$R *.dfm}
function GetIconFromExe(ExeName:String):HIcon;
Var ic:longint;
idx:longint;
Exewidechar;
begin
getmem(Exe,255);
stringtowidechar(ExeName,Exe,255);
ic:=SHChangeIconDialog(form1.handle,Exe,0,idx);//调用图标更换对话框
if ic<>0 then //成功调用
result:=extracticon(0,pchar(widechartostring(Exe)),idx);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Filter := '图标库(*.ico;*.exe;*.dll;*.icl)|*.ico;*.exe;*.dll;*.icl';
if OpenDialog1.Execute then
Image1.Picture.Icon.Handle := GetIconFromExe(Opendialog1.fileName);
end;
end.