L
lfpsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
使用如下的代码,在98中是没有问题的.但是在xp中就有问题了,无论打开什么文件,都会先弹
出一个警告,说“Windows无法找到文件”后面还有一串乱码,然后才弹出图标更换对话框.
如果什么参数也不输入,则也没有问题.
哪位高手知道这到底是什么问题吗?
-----------------------------------------------------------------
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;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Function SHChangeIconDialog(hOwner:hwnd;szFilenamechar;Reserved:longint; var lpIconIndex:Longint):Longint;stdcall;external 'shell32' index 62;
{$R *.dfm}
function GetIconFromExe(ExeName:String):HIcon;
Var ic:longint;
idx:longint;
Exechar;
begin
getmem(Exe,255);
Exe:=pchar(ExeName); //参数可以为空串,看看结果是什么?
ic:=SHChangeIconDialog(form1.handle,Exe,0,idx);
if ic<>0 then //成功调用
result:=extracticon(0,Exe,idx);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Image1.Picture.Icon.Handle := GetIconFromExe(Opendialog1.fileName);
end;
end.
出一个警告,说“Windows无法找到文件”后面还有一串乱码,然后才弹出图标更换对话框.
如果什么参数也不输入,则也没有问题.
哪位高手知道这到底是什么问题吗?
-----------------------------------------------------------------
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;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Function SHChangeIconDialog(hOwner:hwnd;szFilenamechar;Reserved:longint; var lpIconIndex:Longint):Longint;stdcall;external 'shell32' index 62;
{$R *.dfm}
function GetIconFromExe(ExeName:String):HIcon;
Var ic:longint;
idx:longint;
Exechar;
begin
getmem(Exe,255);
Exe:=pchar(ExeName); //参数可以为空串,看看结果是什么?
ic:=SHChangeIconDialog(form1.handle,Exe,0,idx);
if ic<>0 then //成功调用
result:=extracticon(0,Exe,idx);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Image1.Picture.Icon.Handle := GetIconFromExe(Opendialog1.fileName);
end;
end.