应该是存在动态链接库中吧。 或者资源文件可以用 ExtractIcon 函数提取。如: Private Sub ShowIcon(IconIndex As Integer) 'On Error Resume Next Dim hIcon As Long hIcon = ExtractIcon(App.hInstance, txtIconFile.Text, IconIndex) picIcon.Cls ' DrawIcon Me.hdc, 10, 10, hIcon DrawIcon picIcon.hdc, 10, 10, hIcon lstVIcons.ListItems.Clear lstVIcons.ListItems.Add , , IconIndex ', hIcon picIcon.Line (9, 9)-(42, 42), vbRed, B DestroyIcon hIcon End Sub===================== ExtractIcon The ExtractIcon function retrieves a handle to an icon from the specified executable file, dynamic-link library (DLL), or icon file. To retrieve an array of handles to large or small icons, use the ExtractIconEx function. HICON ExtractIcon( HINSTANCE hInst, // instance handle LPCTSTR lpszExeFileName, // filename of file with icon UINT nIconIndex // index of icon to extract );
Parameters hInst Handle to the instance of the application calling the function. lpszExeFileName Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file. nIconIndex Specifies the zero-based index of the icon to retrieve. For example, if this value is 0, the function returns a handle to 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 95, Windows NT 4.0, and later: If this value is a negative number not equal to -1, the function returns a handle to 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 a 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. Res You must destroy the icon handle returned by ExtractIcon by calling the DestroyIcon function. ======================== ExtractIconEx The ExtractIconEx function creates an array of handles to large or small icons extracted from the specified executable file, dynamic-link library (DLL), or icon file. UINT ExtractIconEx( LPCTSTR lpszFile, int nIconIndex, HICON FAR *phiconLarge, HICON FAR *phiconSmall, UINT nIcons );
Parameters lpszFile Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file from which icons will be extracted. nIconIndex Specifies the zero-based index of the first icon to extract. For example, if this value is zero, the function extracts the first icon in the specified file. If this value is –1 and phIconLarge and phiconSmall are both NULL, 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 95, Windows NT 4.0, and later: If this value is a negative number and either phIconLarge or phiconSmall is not NULL, the function begins by extracting the icon whose resource identifier is equal to the absolute value of nIconIndex. For example, use -3 to extract the icon whose resource identifier is 3. phiconLarge Pointer to an array of icon handles which receives handles to the large icons extracted from the file. If this parameter is NULL, no large icons are extracted from the file. phiconSmall Pointer to an array of icon handles which receives handles to the small icons extracted from the file. If this parameter is NULL, no small icons are extracted from the file. nIcons Specifies the number of icons to extract from the file. Return Values If the nIconIndex parameter is -1, the phiconLarge parameter is NULL, and the phiconSmall parameter is NULL, then the return value is the number of icons contained in the specified file. Otherwise, the return value is the number of icons successfully extracted from the file. Res You must destroy all icons extracted by ExtractIconEx by calling the DestroyIcon function. To retrieve the dimensions of the large and small icons, use theGetSystemMetrics function with the SM_CXICON, SM_CYICON, SM_CXSMICON, and SM_CYSMICON flags. Windows CE: The nIconIndex parameter must be zero or –N where N is a specified resource identifier. The nIcons parameter must be 1.
或者资源文件可以用 ExtractIcon 函数提取。如:
Private Sub ShowIcon(IconIndex As Integer)
'On Error Resume Next
Dim hIcon As Long
hIcon = ExtractIcon(App.hInstance, txtIconFile.Text, IconIndex)
picIcon.Cls
' DrawIcon Me.hdc, 10, 10, hIcon
DrawIcon picIcon.hdc, 10, 10, hIcon
lstVIcons.ListItems.Clear
lstVIcons.ListItems.Add , , IconIndex ', hIcon
picIcon.Line (9, 9)-(42, 42), vbRed, B
DestroyIcon hIcon
End Sub=====================
ExtractIcon
The ExtractIcon function retrieves a handle to an icon from the specified executable file, dynamic-link library (DLL), or icon file. To retrieve an array of handles to large or small icons, use the ExtractIconEx function. HICON ExtractIcon(
HINSTANCE hInst, // instance handle
LPCTSTR lpszExeFileName, // filename of file with icon
UINT nIconIndex // index of icon to extract
);
Parameters
hInst
Handle to the instance of the application calling the function.
lpszExeFileName
Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file.
nIconIndex
Specifies the zero-based index of the icon to retrieve. For example, if this value is 0, the function returns a handle to 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 95, Windows NT 4.0, and later: If this value is a negative number not equal to -1, the function returns a handle to 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 a 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. Res
You must destroy the icon handle returned by ExtractIcon by calling the DestroyIcon function. ========================
ExtractIconEx
The ExtractIconEx function creates an array of handles to large or small icons extracted from the specified executable file, dynamic-link library (DLL), or icon file. UINT ExtractIconEx(
LPCTSTR lpszFile,
int nIconIndex,
HICON FAR *phiconLarge,
HICON FAR *phiconSmall,
UINT nIcons
);
Parameters
lpszFile
Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file from which icons will be extracted.
nIconIndex
Specifies the zero-based index of the first icon to extract. For example, if this value is zero, the function extracts the first icon in the specified file.
If this value is –1 and phIconLarge and phiconSmall are both NULL, 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 95, Windows NT 4.0, and later: If this value is a negative number and either phIconLarge or phiconSmall is not NULL, the function begins by extracting the icon whose resource identifier is equal to the absolute value of nIconIndex. For example, use -3 to extract the icon whose resource identifier is 3. phiconLarge
Pointer to an array of icon handles which receives handles to the large icons extracted from the file. If this parameter is NULL, no large icons are extracted from the file.
phiconSmall
Pointer to an array of icon handles which receives handles to the small icons extracted from the file. If this parameter is NULL, no small icons are extracted from the file.
nIcons
Specifies the number of icons to extract from the file.
Return Values
If the nIconIndex parameter is -1, the phiconLarge parameter is NULL, and the phiconSmall parameter is NULL, then the return value is the number of icons contained in the specified file. Otherwise, the return value is the number of icons successfully extracted from the file. Res
You must destroy all icons extracted by ExtractIconEx by calling the DestroyIcon function. To retrieve the dimensions of the large and small icons, use theGetSystemMetrics function with the SM_CXICON, SM_CYICON, SM_CXSMICON, and SM_CYSMICON flags. Windows CE: The nIconIndex parameter must be zero or –N where N is a specified resource identifier. The nIcons parameter must be 1.