?
Solved

Getting the icon of a file

Posted on 1998-10-03
15
Medium Priority
?
152 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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