Solved

Getting the icon of a file

Posted on 1998-10-03
15
146 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now