Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Icons for Files

Status
Not open for further replies.

huntjr

Programmer
Jun 12, 2000
23
0
0
US
I am writing a program that has a small feature of viewing files like Windows Explorer but simpler. I need a way of calling some API function(s) or something to grab the icon for a file (like the piece of paper out of a spiral notebook of text files, etc.), and if it's an application, its icon. The target platform is mostly Win95, not 98, and I know I can't use the Shell object without the IE4 integration.
 
This is the code that we use (on NT)<br><br>It's part of a larger module and I *think* I've got all the dependencies here - let me know if it doesn't work.<br><br><FONT FACE=monospace><b><br>Option Explicit<br>Public Declare Function ExtractIcon Lib &quot;shell32.dll&quot; Alias &quot;ExtractIconA&quot; ( _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal hInst As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal lpszExeFileName As String, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal nIconIndex As Long _<br>) As Long<br><br>Public Sub Doit()<br>Dim hRASIcon As Long<br><br>&nbsp;&nbsp;&nbsp;&nbsp;hRASIcon = ExtractIcon(hwnd, &quot;rasadmin.exe&quot;, 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;Call DrawIcon(Picture1.hdc, 0, 0, hRASIcon)<br>&nbsp;&nbsp;&nbsp;&nbsp;Picture1.Refresh<br><br>End Sub<br></font></b> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
oh - and this one<br><FONT FACE=monospace><b><br>Declare Function DrawIcon Lib &quot;user32&quot; ( _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal hdc As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal x As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal y As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal hIcon As Long _<br>) As Long<br></font></b><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thank you very much for your help. Can you specify the size to retrieve (16x16 for detail view and 32x32 for large icon view, etc.)? And once it is put in the picture box, how do you add the image to an imagelist for use with a listview control? I know that when I see it, I'll kick myself, but I just can't figure it out. <p>Phil Hunt<br><a href=mailto:philh@dqc.com>philh@dqc.com</a><br><a href= > </a><br>
 
image list - don't know but I'll have a look<br><br>image size, hmmm. I would have assumed that you would need two images, one for each size. My approach would be too take a 32x32 icon and resize it using Painshop or similar; but I don't know much about graphics.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
I need to do this at runtime. You can customize what program opens what file and what the Icon looks like (associations). I need to grab the icon. <p>Phil Hunt<br><a href=mailto:philh@dqc.com>philh@dqc.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top