Declare Function PickIconDlg Lib "shell32.dll" Alias "#62" (ByVal hwndOwner As Long, ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As Long) As Long
PickIconDlg displays the standard Windows "icon selection" dialog box. It allows the user to choose an icon found inside a file. The function then reports which icon the user selected, if any.
Windows NT, 2000: All strings used by this function must be Unicode. Therefore, any strings passed to the function must first be converted into Unicode. Likewise, any strings output by the function also must be converted from Unicode into ANSI.
If successful, the function returns a non-zero value. If an error occured or the user did not choose an icon (for example, the user clicked "Cancel"), the function returns 0.
None.
' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function PickIconDlg Lib "shell32.dll" Alias "#62" (ByVal hwndOwner As Long, _ ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As Long) As Long Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Public Const VER_PLATFORM_WIN32_NT = 2 Public Const VER_PLATFORM_WIN32_WINDOWS = 1 Public Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst _ As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal x As Long, _ ByVal y As Long, ByVal hIcon As Long) As Long Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" _ (ByVal lpBuffer As String, ByVal nSize As Long) As Long ' When the user presses button Command1, display an icon selection dialog box. If the ' user chooses an icon, then draw it in the corner of window Form1's client area. Private Sub Command1_Click() Dim iconfile As String ' file that contains the desired icon Dim iconindex As Long ' index of the desired icon Dim slength As Long ' length of returned string Dim hIcon As Long ' handle to the icon once it is extracted Dim ovi As OSVERSIONINFO ' identifies the Windows platform Dim retval As Long ' return value ' First, determine if the computer is running Windows NT or 2000. In either case, ' all strings used with PickIconDlg must be converted into Unicode. ovi.dwOSVersionInfoSize = Len(ovi) retval = GetVersionEx(ovi) ' Figure out where the System directory is. iconfile = Space(256) slength = GetSystemDirectory(iconfile, Len(iconfile)) iconfile = Left(iconfile, slength) ' Have the default selection be the third icon in pifmgr.dll. Include plenty ' of extra space in the string so it can receive the user's selection. iconfile = iconfile & "\pifmgr.dll" & vbNullChar & Space(256) iconindex = 2 ' Display the icon selection dialog. If Windows NT or 2000 is running, convert ' the string to and from Unicode immediately before and after calling the function. If ovi.dwPlatformId = VER_PLATFORM_WIN32_NT Then iconfile = StrConv(iconfile, vbUnicode) End If retval = PickIconDlg(Form1.hWnd, iconfile, Len(iconfile), iconindex) If ovi.dwPlatformId = VER_PLATFORM_WIN32_NT Then iconfile = StrConv(iconfile, vbFromUnicode) End If ' Remove the terminating null and empty space from the string. iconfile = Left(iconfile, InStr(iconfile, vbNullChar) - 1) ' If the user selected something, draw the icon on Form1. If retval <> 0 Then ' Extract the icon from the file. hIcon = ExtractIcon(App.hInstance, iconfile, iconindex) ' Draw it in the corner of the window. retval = DrawIcon(Form1.hDC, 0, 0, hIcon) ' Destroy the icon to free resources. retval = DestroyIcon(hIcon) End If End Sub
Shell
Back to the Function list.
Back to the Reference section.
Last Modified: June 4, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/p/pickicondlg.html