Solved

Clean images for directory component

Posted on 1998-07-31
12
389 Views
Last Modified: 2010-04-04
Hello All
   I am writing a component which will display files under a directory. I am currently using ExtractAssociatedIcon to load the files associated icon. I am not happy with the quality of the image. I have to have a dead clean interface that will be very Win 95 like. I suspect something to do with the resolution (I think the icons are 15 X 15) because Win 95 displayed icons are 35 X 35. Any great ideas how to circumvent this are appreciated.
   The component is based on TCustomListBox, and I am using D3 under Win95.

Regards,
Edo
0
Comment
Question by:Edo082297
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359371
Edo, so what is the question?
0
 
LVL 2

Expert Comment

by:freter
ID: 1359372
Edo:
You can use the system icon list. The icons in this list are exactly the size ones needs.
You can find information on how to access this list in a prototype of an explorer I have put here:
http://delphi.nordakademie.de/down/exlsrc.zip

Cheers, Freter
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359373
Edo, see some other controls with sources to learn maybe. I'm not sure they are much better though.

                  http://sunsite.icm.edu.pl/delphi/ftp/d10free/calmir10.zip
      " icon based file manager, explorer tree, shortcuts, bin etc.."

                         http://bes.trendline.co.il/torry/vcl/lbcb/flist230.zip
      "TFileList is a ListView specialized for file listing in an Explorer-like way."

                         http://home.t-online.de/home/mirbir.st/dirtree.zip
      "TreeView to display the system's drives and folders (also custom files)."

                         http://bes.trendline.co.il/torry/vcl/lbcb/expbox.zip
      "This component combines both a file listbox and a directory listbox to create an Explorer-style navigation and file selection listbox. Now it looks more like "original" control. Added icons for files."
0
 
LVL 1

Author Comment

by:Edo082297
ID: 1359374
ZifNab, I want great looking icons, like the ones in Explorer. My comp works (ExtractAssociatedIcon), but the icons look like garbage. I want to know how Windows does this. My question purely concerns purely cosmetics.

Freter, I will check out your idea.

Matvey (sorry, I'm male ;) I have checked out all but one of those comps. I don't think the other one will help, unless it is really slick. I will check it out, however, and get back to this thread.

Thanks all,
Edo
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1359375
Hi,
Are you using TImageList(.Draw)? I use it often under these conditions, and it always seems to do the job.

BTW: My system icons are always 32x32 or 16x16 and most executable/library(dll) icons are of these sizes (though deviations might occur).

If you scale a 16x16 icon into a 15x15 rect there will be jitter effects (of course :-) and that will make the icon look like crap (in most cases).

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359376
Edo, just a Q'n why don't you just use ExtractIcon?

Haven't used this, but found something interesting on the net, about LR_COPYFROMRESOURCE. Will you try it out?


------------
I'm guessing here, but I think what you need to do is go ahead and extract the
icon that way, and then use CopyImage to get the 16x16 version. Here's an
excerpt from the Win32.hlp file that explains it a little bit:

fuFlags
  Specifies a combination of the following values:

  Value Meaning
  {....}
  LR_COPYFROMRESOURCE Windows 95 only: Tries to reload an icon or cursor
resource from the original resource file rather than simply copying the
current image. This is useful for creating a different-sized copy when the
resource file contains multiple sizes of the resource. Without this flag,
CopyImage stretches the original image to the new size. If this flag is set,
CopyImage uses the size in the resource file closest to the desired size.This
will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by
LoadImage with the LR_SHARED flag.


The only problem now is that this constant is missing from the Delphi Windows
unit. What I do is just add it to my own unit like this:

const
  LR_COPYFROMRESOURCE = $4000; // Missing from WINDOWS.PAS!

   [ZifPS. : In D3.x this one IS declared!]

and then I use CopyImage like this:

var
  SmallIcon: HIcon;
  Size: integer;
begin
  { I want the small icon size }
  Size := GetSystemMetrics(SM_CXSMICON);
  { Assume IconHandle is a valid HIcon }
  SmallIcon := CopyImage(IconHandle, IMAGE_ICON, Size, Size,
LR_COPYFROMRESOURCE);
 
  { Do whatever you want with the small icon here. }

  { Don't forget to clean up what you created }
  DestroyIcon(SmallCopy);
end;


Hope that helps.


Regards,
Brad Stowers
-----------------

Regards, Zif.
0
IT, Stop Being Called Into Every Meeting

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!

 
LVL 4

Accepted Solution

by:
BoRiS earned 70 total points
ID: 1359377
edo

(Sorry everyone but I think he is looking for this API call...)

the API call is SHGetFileInfo and it works like so...

uses
         ..., ShellApi;

       procedure TForm .........
       var
         SmallIco: TIcon;
         shfi: TShFileInfo;
       begin
         SmallIco := TIcon.Create;
         ZeroMemory(@shfi, SizeOf(shfi));
         ShGetFileInfo('C:\MyFile.exe', 0, shfi, SizeOf(shfi), SHGFI_SMALLICON);
         SmallIco.Handle := shfi.hIcon;
         ... {rest of coding}
         SmallIco.Free;
       end;

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1359378
edo

This API call is what is used by windows to retrieve the small icon of an application, like in the windows explorer...

Later
BoRiS

0
 
LVL 1

Author Comment

by:Edo082297
ID: 1359379
Hiya

BoRiS, I tried in vain to get that code to work. The handle returned is always zero. I suspect that some of the necessary parameters for the FILEINFO struct are missing. Do you know which one(s) perchance? On a side note, go back to the question to all....new one? where I wrote something that may interest you. It was the question where a lot of people were revealing their personal and professional interests.

Brad, CopyImage certainly works better, but it is still not good enough (grrrr). BTW, ExtractAssociatedIcon does the same thing as ExtractIcon, only that Windows will look up the associated icon for the file relative to the .exe for you. AND BTW, I have learned a hell of a lot from your components, thankyou very much. BrowseFolder is pretty heavy!! (That one is yours, neh?)

Freter, I perused your code. Good stuff. However, I could not determine exactly what I required to extract the system icon, because there is a lot of manipulation of the struct prior to the actual call. I gather I have to create an image list, and populate it, (no problem) but I could not reduce it to comprise only relative code while examining it (briefly, of course ;). There is a fair amount going on there. Could you tell me the bare requirements? I could then show the correct image through your function (GetIconIndex) which returns the index of the correct image.

I would really like to get BoRiSs\ Freters method to work, does anyone know what could be missing? They both employ the SHGetFileInfo API....

Regards
Edo
0
 
LVL 1

Author Comment

by:Edo082297
ID: 1359380
Hi
I found an example that I had in an old UNDU and got it to display small icons using the API, looks like I should find the bug pretty soon.
I also got the Network Neighborhood to work using enumerations and the like. Is there a simpler way to do this (probably not!).

Edo
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1359381
Edo

replace the code I left with this code...

procedure TForm1.Button1Click(Sender: TObject);
       var
             SmallIco: TIcon;
             shfi: TShFileInfo;
           begin
             SmallIco := TIcon.Create;
             ZeroMemory(@shfi, SizeOf(shfi));
             ShGetFileInfo('D:\Windows\explorer.exe', 0, shfi, SizeOf(shfi), SHGFI_SMALLICON or SHGFI_ICON);
             SmallIco.Handle := shfi.hIcon;
              Application.Icon := SmallIco;
              //Image1.Picture.Icon := SmallIco;
             SmallIco.Free;
           end;

Later
BoRiS
0
 
LVL 1

Author Comment

by:Edo082297
ID: 1359382
Hi Boris
   I apologize for the mediocre grade, and taking so long to grade it. I may be being mean, but I have an entirely better way to do this. I now obtain a handle to the image list maintained by Windows, and associate it with my component's image list. I use the system image list to display the appropriate bitmap associated with the file. However, I have another problem which you can read about in my question entitled "Associating system image list bitmaps with drives".

Regards,
Edo

P.S. You never answered my query in the question entitled, 'to all...new one?'

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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