ExtractIcon API 
Author Message
 ExtractIcon API

How do I use ExtractIcon API -- how do I apply the parameters and the
result?




Fri, 15 Sep 2000 03:00:00 GMT  
 ExtractIcon API

Here's an old example.
How to Extract a Windows Program Icon -- Running or Not
Q88944

As always, in the Knowledge Base.

I believe the better question is how do you then save the extracted icon.
The example allows you to "paste" it but the best I could save was as a
bitmap.  Once I got the icons to save, but the Left, topmost pixel defined
the transparency colour. *sigh*



Quote:
> How do I use ExtractIcon API -- how do I apply the parameters and the
> result?





Sat, 16 Sep 2000 03:00:00 GMT  
 ExtractIcon API

This is from MSDN

ExtractIcon
The ExtractIcon function retrieves the handle of an icon from the specified
executable file, dynamic-link library (DLL), or icon file.
HICON ExtractIcon(
  HINSTANCE hInst,          // instance handle
  LPCTSTR lpszExeFileName,  // filename of file with icon
  UINT nIconIndex           // index of icon to extract
);

Parameters
hInst - Identifies the instance of the application calling the function.
lpszExeFileName - Points to a null-terminated string specifying the name of
an executable file, DLL, or icon file.
nIconIndex - Specifies the index of the icon to retrieve.
If this value is 0, the function returns the handle of the first icon in the
specified file.
If this value is -1, the function returns the total number of icons in the
specified file. If the file is an executable file or DLL, the return value
is the number of RT_GROUP_ICON resources. If the file is an .ICO file, the
return value is 1.

Windows NT 4.0 and later: If this value is a negative number not equal
to -1, the function returns the handle of the icon in the specified file
whose resource identifier is equal to the absolute value of nIconIndex. For
example, use -3 to extract the icon whose resource identifier is 3. To
extract the icon whose resource identifier is 1, use the ExtractIconEx
function.

Return Values
The return value is the handle to an icon. If the file specified was not an
executable file, DLL, or icon file, the return is 1. If no icons were found
in the file, the return value is NULL.

Remarks
You must destroy the icon handle returned by ExtractIcon by calling the
DestroyIcon function.

QuickInfo
  Windows NT: Use version 3.1 and later.
  Windows: Use Windows 95 and later.
  Windows CE: Unsupported.
  Header: Declared in shellapi.h.
  Import Library: Link with shell32.lib.

Quote:

>How do I use ExtractIcon API -- how do I apply the parameters and the
>result?





Sat, 16 Sep 2000 03:00:00 GMT  
 ExtractIcon API

start a new project, put command button on it,then a picture box

Open the declarations and paste the following in it, and run it.
******************************************************************
Option Explicit

Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal
xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As
Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal
hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal
hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long,
ByVal n2 As Long, ByVal un2 As Long)
'Declare Function LoadImageBynum Lib "user32" Alias "LoadImageA" (ByVal
hInst As Long, ByVal lpsz As Long, ByVal un1 As Long, ByVal n1 As Long,
ByVal n2 As Long, ByVal un2 As Long)
'Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias
"GetModuleHandleA" (ByVal lpModuleName As String) As Long
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 DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x
As Long, ByVal y As Long, ByVal hIcon As Long) As Long
'Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias _
    "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As
String,

Private Sub ShowExeDll(FileParam)

Dim myhInst As Long
Dim hIcon As Long
Dim IconNo As Long
Dim r As Long

On Error GoTo thisend

'Use only with your program running in the environment.
         'myhInst = GetModuleHandle("myapp.exe")
         myhInst = GetModuleHandle("VB5.exe")

'get # of Icons

hIcon = ExtractIcon(myhInst, FileParam, -1)

If hIcon = 0 Then
    'Label1.Caption = "No icons in this file!"
    Exit Sub
End If

Dim Tempi As Integer
Tempi = 1

'For Tempi = 1 To hIcon 'i SKIP THIS FOR YOU
    Picture1.Cls
    IconNo = ExtractIcon(myhInst, FileParam, Tempi)
    r = DrawIconEx(Picture1.hdc, 0, 0, IconNo, 32, 32, 0, 0, 3)
'Next Tempi

'Label1.Caption = "Total Number = " & hIcon
'ListView1.Sorted = True

On Error Resume Next

If Err.Number Then

End If

Exit_thisend:
Exit Sub

thisend:
MsgBox Err.Description
Resume 'Next
End Sub

Private Sub Command1_Click()
ShowExeDll "C:\Windows\System\Shell32.dll"
End Sub

***************************************************************
Hope that helps

--
Donald A. Herman
Anidesk 2.1  Animated Desktop Icons
Ani and Icon Browsers, Scheduler Pro
VB5 Resources
http://www.fcs-net.com/~dherman/index.htm



Quote:
> How do I use ExtractIcon API -- how do I apply the parameters and the
> result?





Sat, 16 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Icons, extracticon API

2. ExtractIcon api call and then saving the icon to a file (HELP)

3. Icons, extracticon API

4. Icons, extracticon API

5. ExtractIcon API:NewBie needs help

6. Icons, extracticon API

7. How do I save an icon from ExtractIcon API to file or in an imagelist?

8. VB4.0 ExtractIcon, DrawIcon API calls

9. API: Using ExtractIcon and .Picture property

10. Icons - How to gain access to the Mask, image as well as the Color-table : ExtractIcon

11. Icons - How to gain access to the Mask, image as well as the Color-table : ExtractIcon

12. List View (Report) and ExtractIcon

 

 
Powered by phpBB® Forum Software