ExtractAssociatedIcon() to picture object?

ExtractAssociatedIcon() to picture object?

Post by Troy Youn » Wed, 08 Jul 1998 04:00:00



Does anyone have any sample code that shows how to get the icon represented
by the handle returned by the ExtractAssociatedIcon() function into a
picture object or image list?  Or, for that matter, sample code that
demonstrates how to use ExtractAssociatedIcon (or ExtractIcon) in VB?

TIA,
Troy Young
  Ventana Corporation

 
 
 

ExtractAssociatedIcon() to picture object?

Post by Blake Wilso » Thu, 09 Jul 1998 04:00:00


Troy,

I tried to reply to your message but the email address you supplied is
incorrect :(

Blake Wilson



 
 
 

ExtractAssociatedIcon() to picture object?

Post by Troy Youn » Thu, 09 Jul 1998 04:00:00



>I tried to reply to your message but the email address you supplied is
>incorrect :(

Sorry--I forgot to mention in my message that you need to remove the
"nospam" to reply.

Troy Young
  Senior Software Engineer
  Ventana Corporation

    (remove "nospam" to reply)

 
 
 

ExtractAssociatedIcon() to picture object?

Post by mprope » Thu, 09 Jul 1998 04:00:00



> Does anyone have any sample code that shows how to get the icon represented
> by the handle returned by the ExtractAssociatedIcon() function into a
> picture object or image list?  Or, for that matter, sample code that
> demonstrates how to use ExtractAssociatedIcon (or ExtractIcon) in VB?

> TIA,
> Troy Young
>   Ventana Corporation


Put this in a module :

Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias
"ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String,
lpiIcon As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal
hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As
Long

Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal X As Long,
ByVal Y As Long, ByVal hIcon As Long) As Long

Put a picturebox called picIcon in a form , and put this somewhere in the form
:

For ExtractAssociatedIcon :

hIcon& = ExtractAssociatedIcon(Me.hdc, "C:\windows\win.ini", 0)  ' 0 is the
icon

R% = DrawIcon(picIcon.hdc, 0, 0, hIcon&) 'Draw the icon in the picture box

For ExtractIcon :

hIcon& = ExtractIcon(Me.hdc, "C:\windows\notepad.exe", 0)  ' moricons.dll
contains 116 icons, you can replace 0 width another number

R% = DrawIcon(picIcon.hdc, 0, 0, hIcon&) 'Draw the icon in the picture box



Bye!

 
 
 

ExtractAssociatedIcon() to picture object?

Post by Sebastian Odin Smit » Fri, 10 Jul 1998 04:00:00


Troy,

I have a routine that uses ExtractIcon. You could modify it to use
ExtractAssociatedIcon with little difficulty.

'============================================
'CODE BEGINS HERE
'============================================
Private Type PICDEST_TYPE
   lSize As Long
   lType As Long
   hBMP As Long
   hPal As Long
   hNonBMPObj As Long
End Type

Private Type GUID_TYPE
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(7) As Byte
End Type

Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
( _
   ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As
Long) As Long

Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" ( _
   PicDesc As PICDEST_TYPE, RefIID As GUID_TYPE, ByVal fPictureOwnsHandle&,
_
   IPic As IPictureDisp) As Long

Public Function GetModuleIcon(ByVal sModule As String) As IPictureDisp

   Dim llhIcon As Long
   Dim lobjPic As IPicture
   Dim ltGUID As GUID_TYPE
   Dim ltPicDest As PICDEST_TYPE

   On Error Resume Next

   With ltGUID
      .Data1 = &H20400
      .Data4(0) = &HC0
      .Data4(7) = &H46
   End With

   With ltPicDest
      .lSize = Len(ltPicDest)
      .lType = vbPicTypeIcon
   End With

   Set GetModuleIcon = LoadResPicture(14001, vbResIcon) 'default icon for my
app

   If Len(Dir$(sModule)) Then
      sModule = sModule & Chr$(0)
      llhIcon = ExtractIcon(App.hInstance, sModule, 0&)
      If llhIcon > 1 Then
         ltPicDest.hBMP = llhIcon
         If OleCreatePictureIndirect(ltPicDest, ltGUID, 1, lobjPic) = 0 Then
            Set GetModuleIcon = lobjPic
         End If
         Call DeleteObject(llhIcon)
      End If
   End If

End Function

'============================================
END CODE
'============================================


>Does anyone have any sample code that shows how to get the icon represented
>by the handle returned by the ExtractAssociatedIcon() function into a
>picture object or image list?  Or, for that matter, sample code that
>demonstrates how to use ExtractAssociatedIcon (or ExtractIcon) in VB?

>TIA,
>Troy Young
>  Ventana Corporation


 
 
 

ExtractAssociatedIcon() to picture object?

Post by Troy Youn » Fri, 10 Jul 1998 04:00:00


Very close, but that doesn't actually put the icon in the picture object--it
just displays it.

Blake Wilson's response takes the final step.

Thanks,
Troy

 
 
 

ExtractAssociatedIcon() to picture object?

Post by Troy Youn » Fri, 10 Jul 1998 04:00:00



>Here is your solution.

> <snip>

Thanks!  That's exactly what I needed.

Actually, an even better solution would be one that uses a memory DC so that
I don't have to use a picture control, but this will work fine.

Thanks again,
Troy

 
 
 

ExtractAssociatedIcon() to picture object?

Post by Troy Youn » Wed, 15 Jul 1998 04:00:00



>Troy,

>I have a routine that uses ExtractIcon. You could modify it to use
>ExtractAssociatedIcon with little difficulty.

Hmm.  Very cool code.  I actually have it working w/ Picture controls, but
I'd like to try your approach when I get time.

Thanks,
Troy