Jag får inte SHChangeIconDialog att fungera på mitt XP system. Jag får fram dialogen och får tillbaka icon indexet men inte filen som användern valt. Den funktionen fungerar nog perfekt, snarare är det nog lite problem med din kod... Kan du klistra in den i ett nytt inlägg tror du? :) Skulle inte förvåna mig det minsta: Jag ser inget direkt fel i koden, men du kan ju alltid testa lite kod saxad ifrån api-guide:SHChangeIconDialog
Sv: SHChangeIconDialog
Sv: SHChangeIconDialog
Dim sFilename As String
Dim nIconIdx As Long ' 0 on init
Dim hSmallIcon As Long
Dim hLargeIcon As Long
' Allocate rtn buffer
sFilename = MakeMaxPath(txtIconPath)
If g_fIsWinNT Then sFilename = StrConv(sFilename, vbUnicode)
nIconIdx = txtIconIdx
' Rtns 1 if selection, 0 if cancelled
If SHChangeIconDialog(hWnd, sFilename, 0, nIconIdx) Then
' Display selection
txtIconPath = GetStrFromBuffer(sFilename)
txtIconIdx = nIconIdx
end if
där MakeMaxPath() fixar så att den blir 260 lång och det "lediga" utrymmet flyssa med nullcharen, Nämans bör att jag kör på en XP Pro maskin.Sv: SHChangeIconDialog
<code>
Private Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function SHChangeIconDialogA Lib "shell32" Alias "#62" (ByVal hOwner As Long, ByVal szFilename As String, ByVal Reserved As Long, lpIconIndex As Long) As Long
Private Declare Function SHChangeIconDialogW Lib "shell32" Alias "#62" (ByVal hOwner As Long, ByVal szFilename As Long, ByVal Reserved As Long, lpIconIndex As Long) As Long
'Detect if the program is running under Windows NT
Public Function IsWinNT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
End Function
Public Function chooseIcon(ByRef strFile As String, ByRef lngIconNum As Long) As Boolean
Dim str1 As String * 260
Dim lng1 As Long ' Dummy?
Dim lngResult As Long
str1 = strFile & vbNullChar
'is this code executed under WinNT?
If IsWinNT Then
'if we're in WinNT, we have to call the Unicode version of the function
lngResult = SHChangeIconDialogW(Me.hWnd, StrPtr(str1), lng1, lngIconNum)
Else
'if we're in Win9x, we have to call the ANSI version of the function
lngResult = SHChangeIconDialogA(Me.hWnd, str1, lng1, lngIconNum)
End If
'The function itself returns 0 (failed) or 1 (success)
'str1 is adapted to the selected filename
chooseIcon = (lngResult <> 0)
If chooseIcon Then
strFile = Left$(str1, InStr(1, str1, vbNullChar, vbBinaryCompare) - 1)
End If
End Function
</code>