Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the icon of a file

Posted on 1998-10-03
15
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

604 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