The ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.
Example

VB Code:
  1. 'This project needs a PictureBox, called 'Picture1'
  2.  
  3. 'In general section
  4. Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
  5. Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
  6. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  7.  
  8. Private Sub Form_Load()
  9.  
  10. Dim Path As String, strSave As String
  11. 'Create a buffer string
  12. strSave = String(200, Chr$(0))
  13. 'Get the windows directory and append '\REGEdit.exe' to it
  14. Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave))) + "\REGEdit.exe"
  15. 'No pictures
  16. Picture1.Picture = LoadPicture()
  17. 'Set graphicmode to 'persistent
  18. Picture1.AutoRedraw = True
  19. 'Extract the icon from REGEdit
  20. return1& = ExtractIcon(Me.hWnd, Path, 2)
  21. 'Draw the icon on the form
  22. return2& = DrawIcon(Picture1.hdc, 0, 0, return1&)
  23.    
  24. End Sub