Get system icons under NT

Hi,
Like the title says ;)
I'm currently using something like sicons.handle:=shgetfileinfo('', ect . I don't remember exactly
but it is working, under 95 ar least.
Why it is not working under NT, how should I do ?
I want a tlistimage containing the system icon list.
LVL 4
jeurkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

interCommented:
Hi friend,

it is as follows:

procedure GetSysIcons;
var
 SysImList: HImageList;
 SFI: TSHFileInfo;
begin
  Images := TImageList.Create(Self); //This var should be declared in unit scope
  SysImList := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  if SysImList <> 0 then begin
    Images.Handle := SysImList;
    Images.ShareImages := TRUE;  // DON'T FREE THE SYSTEM IMAGE LIST!!!!!
  end;
end;

and DO NOT FORGET TO call Image.Free upon terminating


Regards,
Igor
0
jeurkAuthor Commented:
thank for the suggestion
It will take me probably until monday to check this out.
So please be patient with grade ;)
Jeurk
0
interCommented:
No problem,

But if you do not have Delphi 3 be sure you have ShellObj.pas for interfacing shell functionality.

Bye,
Igor
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

jeurkAuthor Commented:
Hi,
I tryed the thing, but it is not working under NT4.
I was already doing something similar anyway:

           Images.Handle :=  := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
           Images.ShareImages := TRUE;  

Do you have NT ?
maybe you could make litle prog that shows a drive icon, that you will check out on NT4
and give it over to me.
I will add some points if you need them ;)
Jeurk

PS:maybe what you sayd works, but I made something other wrong.
0
interCommented:
I tried this on NT with Delphi 2.0 and it work. Bind form1click to the forms click method. Run it and click on form.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
uses ShellApi;

var
  Images : TImageList;

procedure GetSysIcons;
var
 SysImList: THandle;
 SFI: TSHFileInfo;
begin
  Images := TImageList.Create(nil); //This var should be declared in unit scope
  SysImList := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or
SHGFI_LARGEICON);//replace this with SHGFI_SMALLICON for retreving small icons
  if SysImList <> 0 then begin
    Images.Handle := SysImList;
    Images.ShareImages := TRUE;  // DON'T FREE THE SYSTEM IMAGE LIST!!!!!
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  GetSysIcons;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Images.Free;
end;

procedure TForm1.FormClick(Sender: TObject);
var
  i,x,y : integer;
begin
  for i := 0 to Images.Count - 1 do
  begin
    x := i*32 mod Form1.ClientWidth;
    y := (i*32 div Form1.ClientWidth)*32;
    Images.Draw(Canvas,x,y,i);
  end;
end;

end.


Regards,
Igor
0
jeurkAuthor Commented:
Always connected, as I can see ;)
I'll try it out, thanks.
0
jeurkAuthor Commented:
Bad news my friend,

It is working perfectly under 95 as always.But under NT4 service pack 3 French version.
There is only one icon that appear!!!
It's a standard folder icon. Nothing more.
What you think now. ?
0
interCommented:
Ok then,

I withdraw until I (or somebody else) find(s) a solution.

Regards,
Igor
0
jeurkAuthor Commented:
The nt I used was not mine, but a friend.
Let say, I'm gonna try to install the ****ing thing
and try out by myself.
You swear that it is working under NT4 ?
Which service pack ?

John.
0
interCommented:
I have runining NT English US ServicePack3. To day I try something else, namely try to obtain the association list(extract which icon is associated with which extension + sysimage list from the coresponding resource file). This should solve the problem on all versions of windows95+ and WindowsNt3.x+. So, before I swear for it(though I have received about 2 dozen icons with above method) I want to work more.

By the way WHERE ARE THE OTHER EXPERTS???? Come on please lets solve this.

Regards,
Igor
0
jeurkAuthor Commented:
Hello inter,

Thanks for being still here ;)
I have a component that lists all the logical drives avalaible,
my friend says that it is working under nt.
Would you take a look at it, and find out why this is working
and not what we tryed ?
I took a look at it, but I must not be smart enough ;)
What you think ?
John
0
interCommented:
If the copyright is not problem and the component has source sure I want:

inter@kosgeb.tekmer.gov.tr

By the way, all the icons we want and more are in the resource of Shell32.dll in system directory. I may try to extract them for you, or just fetch the ones that need to be used and combine a resource file which is then read into an imagelist. This solution sure works every where but since are not dynamic does not change with system changes(for example desktop themes for win95 which changes all the icons etc)

Regards,
Igor
0
jeurkAuthor Commented:
No, don't extract them from shell32.
It's not what I want. Cause if the user has personnalysed his icons,
my prog won't reflect the changes, You see ?
I just sent the thing.
CU

0
interCommented:
Hi,

I have found the problem my friend. A program can only see the icons that it requested from shell. That means if I explicitly request the icon for 'c:\' for example the icon list grows automatically by one. So tell me what kind of icons you want so that we just call SHGetFileinfo for them and our list (Images contains all of that types). For example we may receive:

1 - All drive icons
2 - All common file associations

For example, the image list contains only 5 items for an initial configuration(I remove all shell related components from my test application, for example when you just add TDriveCombo you receive automatically 8 icons. This is due to the component call SHGetFileInfo for drives at design and runtime). Just add this line after creating calling SHGetFileInfo('',...) in the code above and now you have a icon for hard drives:

SHGetFileInfo(PChar('c:\'),0,Info,SizeOf(TShFileInfo),SHGFI_DISPLAYNAME or 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_LARGEICON)

Waiting for your reply,
Igor

0
jeurkAuthor Commented:
Right cool,
I'd like to have all the logical drive icons like
dsk a:
drive c:
cdrom
removable
ram
audio
network
not connected network
I think I have them all.
If you see one other, don't hesitate to add them.

That things works different between 95 and NT is real shitt.
Oh microsoft.
That guys like you helps me, is real cool.
But that problem should not have been ...
I update the points to 80 for the good work ;)
John
0
interCommented:
Hi there,

So just after the

SysImList := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or
      SHGFI_LARGEICON);//replace this with SHGFI_SMALLICON for retreving small icons

line in the complete unit code above add the following:(declare i:integer;ch:char;)
...
// receive drives (code I took from the unit you sent)
// DRIVE_REMOVABLE,DRIVE_FIXED,DRIVE_REMOTE,DRIVE_CDROM,
// DRIVE_RAMDISK
  for ch := 'A' to 'Z' do
  begin
   S := ch + ':\';
   i := GetDriveType(PChar(S));
   if i in [0,1] then Continue; // Invalid
   SHGetFileInfo(PChar(S),0,SFI,SizeOf(SFI), SHGFI_DISPLAYNAME or SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  end;
// And for any other object call for example explorer.exe
   SHGetFileInfo('c:\winnt\explore.exe',0,SFI,SizeOf(SFI), SHGFI_DISPLAYNAME or SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
..

Anyway what kind of application you are writing?
Bye
Igor
0
jeurkAuthor Commented:
I'll try this out.

About the app,
it's called "free space" and shows you how much free space left is on your drives.
If you want a copy, I'll send it to you.
Anyway it's freeware, but my web page is still not up.

John
0
jeurkAuthor Commented:
It is working my friend.
The solution was there and I could not see it.
Thanks a lot for your help.
Please answer that question so I can graduate it.

0
interCommented:
Hi,

I am happy that its ok. Thanks,

Sincerely,
Igor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeurkAuthor Commented:
See You in other theads.
Thanks again.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.