如何获得图标?(50分)

Y

y97523

Unregistered / Unconfirmed
GUEST, unregistred user!
我想编一个类似word工具栏的东西,调用其他的程序似乎不成问题,只要调用api函数
shellexecute就可以了.不过现在工具拦的图标并不是动态的,我想在为一个按钮指定
一个程序的同时按钮的图标既变成那个程序的图标,应该怎么做呢?是不是应该先把exe
文件中的图标提取成ico文件,然后再指定给按纽?或者有更好的办法?
 
用ExtractIcon!
一个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, FileCtrl,ShellAPI;
type
TForm1 = class(TForm)
Image1: TImage;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
DriveComboBox1: TDriveComboBox;
procedure FileListBox1Click(Sender: TObject);
private
procedure NextIcon;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.NextIcon;
var I:Integer;
FileName:string;
Count:Integer;
begin
// if (FileName<>EditFileName.Text) then
if (FileName<>FileListBox1.FileName) then
begin
FileName:=FileListBox1.FileName;
I:=0;
Count:=ExtractIcon(Application.Handle,PChar(FileName),$FFFFFFFF);
end
else
inc(I);
if (I<Count) then
Image1.Picture.Icon.Handle:=ExtractIcon(Application.Handle,PChar(FileName),I)
else
ShowMessage('No more Images');
end;

procedure TForm1.FileListBox1Click(Sender: TObject);
begin
if FileListBox1.FileName<>'' then
NextIcon;
end;

end.
 
[blue]同意上面的作法。
即:
用ExtractIcon!
一个例子:
unit sample;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, FileCtrl,ShellAPI;
type
TForm1 = class(TForm)
Image1: TImage;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
DriveComboBox1: TDriveComboBox;
procedure FileListBox1Click(Sender: TObject);
private
procedure NextIcon;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.NextIcon;
var I:Integer;
FileName:string;
Count:Integer;
begin
// if (FileName<>EditFileName.Text) then
if (FileName<>FileListBox1.FileName) then
begin
FileName:=FileListBox1.FileName;
I:=0;
Count:=ExtractIcon(Application.Handle,PChar(FileName),$FFFFFFFF);
end
else
inc(I);
if (I<Count) then
Image1.Picture.Icon.Handle:=ExtractIcon(Application.Handle,PChar(FileName),I)
else
ShowMessage('No more Images');
end;

procedure TForm1.FileListBox1Click(Sender: TObject);
begin
if FileListBox1.FileName<>'' then
NextIcon;
end;

end.
[/blue]
 
但是如果是一个控制台程序怎么办?
我觉得好像可以用shell api函数做,但不知是哪一个!
另外,程序每次启动都要从exe文件内取出图标似乎不太好,影响速度(尤其是当
可执行文件比较大,按纽个数比较多时),我觉得应该在第一次时将图标存为ico或图标库
这样下次就可以加快速度.
但是不知具体如何做?
 
晕倒,你保存在磁盘上面,还不是一样要LoadIcon?其实是一样的,没有必要在意这些~~~`
况且一个工具栏有那么多层需要放嘛?那样有什么意义?不要想的太复杂~~~~~~
 
我不认为微软的资源管理器是每次extractIcon的。一定有别的方法的。况且,一个程序内有几个icon是,你怎么决定用哪一个呢?
 
用ExtractIcon获得句柄。
 
关注。同我提的问题有相通之处。大家不防去看看我提的问题。
 

Similar threads

顶部