Solved

Getting the icon of a file

Posted on 1998-10-03
15
147 Views
Last Modified: 2010-04-30
How can i get the icon of a file, say netscape.exe, and set it as the picture for a command button.
0
Comment
Question by:hess
  • 5
  • 3
  • 3
  • +2
15 Comments
 

Author Comment

by:hess
ID: 1437972
Edited text of question
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1437973
You can use some Icon editing programs to browse these files.   You might want to try MicroAngelo... It is shareware.
0
 

Author Comment

by:hess
ID: 1437974
From code... I ned to say command1.picture=???
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1437975
no no no.. you cant do that...
If you Already have an .ICO file on your drive somewhere..

then yes..  Command1.picture  = TheIcon.ico

You have to also set the Style to 1-Graphical

Tey it with the Icons in the Graphics\Icons\...directories..
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1437976
also.. what you CAN do easily.. to get the icon..
is to open WindowsExplorer in LARGE Icons mode..
and find the EXE file.. take a screen shot..
then cut and paste the item in PAINT.. and make a small bmp file.. it wont b and ICO file.. but will be fine for a Command Button.  While in Paint.. give it a Gra Fill to the background.. to match the Comand Button..
colors are RGB(192,192,192)
0
 

Author Comment

by:hess
ID: 1437977
i need to do this all in code... no work arounds.  i need to get the icon of say netscape.exe all from code. I want to ony have the path of the file and some how return it's icon then put it on a command button
0
 
LVL 1

Expert Comment

by:steve06
ID: 1437978
hess,

Here is an address where you can find a project which does what you want:
http://www.geocities.com/SiliconValley/Park/8079/vbsolutions.html

then select the project Extract.

I am not the author (his name is Simon Carter) and the whole credit should go to him.

Steve.
0
 
LVL 2

Accepted Solution

by:
Grdv earned 50 total points
ID: 1437979
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long

Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long, ByVal hIcon As Long) As Long

Private Const SHGFI_ICON = &H100                         '  get icon

Private Type SHFILEINFO
   hIcon As Long                       '  out: icon
   iIcon As Long                       '  out: icon index
   dwAttributes As Long                '  out: SFGAO_ flags
   szDisplayName As String * 260       '  out: display name (or path)
   szTypeName As String * 80           '  out: type name
End Type

Public Function GetIcon(m_PathName as String) As Long
   Dim nRet As Long
   Dim sfi As SHFILEINFO
   If len(dir(m_PathName))>0 Then
   nRet = SHGetFileInfo(m_PathName, 0&, sfi, Len(sfi), SHGFI_ICON Or SHGFI_DISPLAYNAME Or SHGFI_TYPENAME)
   GetIcon = sfi.hIcon
   Else
   MsgBox "File not found"
   GetIcon = 0
   End If
End Function

to get the icon and then if it had been a picture box, you would have used:

DrawIcon Picture1.hdc, 0, 0, GetIcon(**netscape-path**)

I don't know how to pass it to the commandbutton, in my VB (4) you have to do special coding to get pictures on you commandbuttons as far as I know...

// Grdv

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1437980
You could use GetAssociatedIcon() which is an API call..... ;->
0
 

Author Comment

by:hess
ID: 1437981
thank. i figured it out on my own but your answer looks like it'll work so i'll award you the points
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1437982
Whose answer??? I guess Grdv . o O ;->

//Vik
0
 
LVL 2

Expert Comment

by:Grdv
ID: 1437983
hmm... well after all I was first, but you method is less complexed viktornet...
mine comes from a routine to get the complete file information....

// Grdv
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1437984
I just wonder why need info from file, just extract the icon and that's all ;->

Talk to ya 2 L8R Bye
0
 

Author Comment

by:hess
ID: 1437985
a made a tollbar similar to the one that comes with office... i need to to get the icon of a file while only having the relivant path
0
 
LVL 2

Expert Comment

by:Grdv
ID: 1437986
viktornet: I've included a fileinfo dialogbox in my last SDI program...

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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