ExtractAssociatedIcon like Windows Explorer 
Author Message
 ExtractAssociatedIcon like Windows Explorer

Hi !

Is there a way to extract an icon from a file and add it to a
listview, just like Windows Explorer do ???

I've tried with ExtractAssociatedIcon but it seems to be the "big"
icon and when I add it to my listview the image is not very good
looking !

Thanks !



Sun, 10 Feb 2002 03:00:00 GMT  
 ExtractAssociatedIcon like Windows Explorer
Try the System ImageList sample from the CodeBox section of my site.

--
~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s)

Klaus H. Probst
http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~



Quote:
> Hi !

> Is there a way to extract an icon from a file and add it to a
> listview, just like Windows Explorer do ???

> I've tried with ExtractAssociatedIcon but it seems to be the "big"
> icon and when I add it to my listview the image is not very good
> looking !

> Thanks !



Sun, 10 Feb 2002 03:00:00 GMT  
 ExtractAssociatedIcon like Windows Explorer
In ExtractAssociatedIcon, I think that you can set it to show the 16x16 icon
in the settings.

-----------------------------------------------------------
From Alex Russell,



| Hi !
|
| Is there a way to extract an icon from a file and add it to a
| listview, just like Windows Explorer do ???
|
| I've tried with ExtractAssociatedIcon but it seems to be the "big"
| icon and when I add it to my listview the image is not very good
| looking !
|
| Thanks !
|



Sat, 09 Mar 2002 03:00:00 GMT  
 ExtractAssociatedIcon like Windows Explorer
Christian .. ExtractIconEx may do the trick, as will SHGetFileInfo.  for an
example of the latter, take a look a the code in the ListView demos 2 and 4
(code library, common controls section), at http://www.mvps.org/vbnet/

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


| In ExtractAssociatedIcon, I think that you can set it to show the 16x16
icon
| in the settings.
|
|
| -----------------------------------------------------------
| From Alex Russell,



| | Hi !
| |
| | Is there a way to extract an icon from a file and add it to a
| | listview, just like Windows Explorer do ???
| |
| | I've tried with ExtractAssociatedIcon but it seems to be the "big"
| | icon and when I add it to my listview the image is not very good
| | looking !
| |
| | Thanks !
| |
|
|



Sun, 10 Mar 2002 03:00:00 GMT  
 ExtractAssociatedIcon like Windows Explorer

You can use SHGetFileInfo - in my run program - I JUST use SHGetFileInfo - not even ExractAssociatedIcon - If you use it like this

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 Type SHFILEINFO
        hIcon As Long                      '  out: icon
        iIcon As Long          '  out: icon index
        dwAttributes As Long               '  out: SFGAO_ flags
        szDisplayName As String * 255 '  out: display name (or path)
        szTypeName As String * 80         '  out: type name
End Type

Private fleInfo As SHFILEINFO

Const SHGFI_ICON As Long = &H100                         '  get icon
Const SHGFI_DISPLAYNAME As Long = &H200                  '  get display name
Const SHGFI_TYPENAME As Long = &H400                     '  get type name
Const SHGFI_ATTRIBUTES As Long = &H800                   '  get attributes
Const SHGFI_ICONLOCATION As Long = &H1000                '  get icon location
Const SHGFI_EXETYPE As Long = &H2000                     '  return exe type
Const SHGFI_SYSICONINDEX As Long = &H4000                '  get system icon index
Const SHGFI_LINKOVERLAY As Long = &H8000                 '  put a link overlay on icon
Const SHGFI_SELECTED As Long = &H10000                   '  show icon in selected state
Const SHGFI_LARGEICON As Long = &H0                      '  get large icon
Const SHGFI_SMALLICON As Long = &H1                      '  get small icon
Const SHGFI_OPENICON As Long = &H2                       '  get open icon
Const SHGFI_SHELLICONSIZE As Long = &H4                  '  get shell size icon
Const SHGFI_PIDL As Long = &H8                           '  pszPath is a pidl
Const SHGFI_USEFILEATTRIBUTES As Long = &H10             '  use passed dwFileAttribute

Private Sub txtFile_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim temp
    temp = SHGetFileInfo(txtFile.Text, vbNull, fleInfo, Len(fleInfo), &H100)

    If fleInfo.hIcon = 0 Then
        If txtFile.Text = "" Then pctImage.Cls: OldIcon = 0: Exit Sub

        pctImage.Cls
        DrawIcon pctImage.hdc, 0, 0, OldIcon
    Else
        pctImage.Cls
        DrawIcon pctImage.hdc, 0, 0, fleInfo.hIcon
        OldIcon = fleInfo.hIcon
    End If
End Sub

Then it definately works.
I'll e-mail you my run program - it will help a lot.
Just change &H100 to whatever settings that you want (Should be either &H1 or &H101).

SO Check you mail,
    Alex
-----------------------------------------------------------
From Alex Russell,

| In ExtractAssociatedIcon, I think that you can set it to show the 16x16 icon
| in the settings.
|
|
| -----------------------------------------------------------
| From Alex Russell,



| | Hi !
| |
| | Is there a way to extract an icon from a file and add it to a
| | listview, just like Windows Explorer do ???
| |
| | I've tried with ExtractAssociatedIcon but it seems to be the "big"
| | icon and when I add it to my listview the image is not very good
| | looking !
| |
| | Thanks !
| |
|
|



Thu, 14 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Need Information - Explorer Bar like in Windows Explorer/Outlook Express

2. how kill the windows explorer in windows 2000.

3. Integrating to Windows Explorer and Windows 2000

4. Copy read-only liked tables

5. Visual Liking in .Net using TREE VIEW control

6. DDE and the likes

7. Likes CAT and Sport Query

8. Noone likes newbies??

9. TOOLBAR LIKES IE3.0

10. Outlook liked form design

11. Outlook liked form design

12. Outlook liked form design

 

 
Powered by phpBB® Forum Software