Solved

Getting the icon of a file

Posted on 1998-10-03
15
145 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
Comment Utility
Edited text of question
0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
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
Comment Utility
From code... I ned to say command1.picture=???
0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Accepted Solution

by:
Grdv earned 50 total points
Comment Utility
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
Comment Utility
You could use GetAssociatedIcon() which is an API call..... ;->
0
 

Author Comment

by:hess
Comment Utility
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
Comment Utility
Whose answer??? I guess Grdv . o O ;->

//Vik
0
 
LVL 2

Expert Comment

by:Grdv
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
viktornet: I've included a fileinfo dialogbox in my last SDI program...

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now