我需要允许用户选择一个图标,所以我从 shell32 实现了 PickIconDlg 函数。问题是,如果用户选择的路径比我声明的初始路径长,则结果值是用户选择的路径被截断为初始路径的长度。
例如,如果我将初始路径设置为“C:\Windows\System32\shell32.dll”并且用户选择“C:\Users\Public\Documents\TheIcons\Library.dll”,则更新后的字符串值返回为“C:\Users\Public\Documents\TheIc”(即用户选择路径的前 31 个字符,因为初始路径是 31 个字符长)。
我尝试调整传递给 PickIconDlg 的“nMaxFile”值,据我所知,它应该设置路径变量的最大长度。这似乎没有什么不同。
Declare Unicode Function PickIconDlg Lib "Shell32" Alias "PickIconDlg" (ByVal hwndOwner As IntPtr, ByVal lpstrFile As String, ByVal nMaxFile As Integer, ByRef lpdwIconIndex As Integer) As Integer
Public Function GetIconLoc(frmform As Form) As Object()
Dim iconfile As String = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\shell32.dll"
Dim iconindex As Integer ' Will store the index of the selected icon
If PickIconDlg(frmform.Handle, iconfile, 50, iconindex) = 1 Then
MessageBox.Show(iconfile)
Return {iconfile, iconindex}
Else
Return Nothing
End If
End Function
我希望字符串变量 iconfile 包含用户选择的完整路径,因为它的长度小于定义的最大 50 个字符。相反,如上所述,仅返回路径的一部分。