Solved

Get system icons under NT

Posted on 1998-03-26
20
207 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
ID: 1360888
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
ID: 1360889
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
ID: 1360890
No problem,

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

Bye,
Igor
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 4

Author Comment

by:jeurk
ID: 1360891
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
ID: 1360892
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
ID: 1360893
Always connected, as I can see ;)
I'll try it out, thanks.
0
 
LVL 4

Author Comment

by:jeurk
ID: 1360894
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
ID: 1360895
Ok then,

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

Regards,
Igor
0
 
LVL 4

Author Comment

by:jeurk
ID: 1360896
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
ID: 1360897
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
 
LVL 4

Author Comment

by:jeurk
ID: 1360898
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
ID: 1360899
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
ID: 1360900
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
ID: 1360901
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
ID: 1360902
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
ID: 1360903
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
ID: 1360904
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
ID: 1360905
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
ID: 1360906
Hi,

I am happy that its ok. Thanks,

Sincerely,
Igor
0
 
LVL 4

Author Comment

by:jeurk
ID: 1360907
See You in other theads.
Thanks again.

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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