|
||||
ExtractIconCategory: IconHits: 4744 Rating: (2.84) votes 1464
Rate: 1-star 2-stars 3-stars 4-stars 5-stars
API Explanation
The ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file. Parameter Information Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long · 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 function succeeds, 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.
Code
'This project needs a PictureBox, called 'Picture1'
'In general section Private Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, _ ByVal y As Long, ByVal hIcon As Long) 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 GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer _As String, ByVal nSize As Long) As Long Private Sub Form_Load() Dim Path As String, strSave As String 'Create a buffer string strSave = String(200, Chr$(0)) 'Get the windows directory and append '\\REGEdit.exe' to it Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave))) + "\\REGEdit.exe" 'No pictures Picture1.Picture = LoadPicture() 'Set graphicmode to 'persistent Picture1.AutoRedraw = True 'Extract the icon from REGEdit return1& = ExtractIcon(Me.hWnd, Path, 2) 'Draw the icon on the form return2& = DrawIcon(Picture1.hdc, 0, 0, return1&) End Sub |