Solved

Get system icons under NT

Posted on 1998-03-26
20
205 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:jeurk
  • 11
  • 9
20 Comments
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
thank for the suggestion
It will take me probably until monday to check this out.
So please be patient with grade ;)
Jeurk
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
No problem,

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

Bye,
Igor
0
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
Always connected, as I can see ;)
I'll try it out, thanks.
0
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
Ok then,

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

Regards,
Igor
0
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 4

Author Comment

by:jeurk
Comment Utility
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
 
LVL 5

Accepted Solution

by:
inter earned 80 total points
Comment Utility
Hi,

I am happy that its ok. Thanks,

Sincerely,
Igor
0
 
LVL 4

Author Comment

by:jeurk
Comment Utility
See You in other theads.
Thanks again.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now