Icon Dialog

Sandos

New member
Joined
Feb 7, 2004
Messages
3
How do I call the Icon Dialog from vb.net ?

Code:
Declare Function SHChangeIconDialog Lib "shell32" Alias "#62" _
>                                (ByVal hOwner As Long, _
>                                ByVal szFilename As String, _
>                                ByVal Reserved As Long, _
>                                lpIconIndex As Long) As Long
>

Just doesnt seem to be right in the new .net way of doing things... i.e what do I do with the hWND ?

Could someone please point me to a .net example (I have searched the net for hours with no luck) or tell me the correct way of calling and handling the returns of this thing.

Any help is appreciated.

Many thanks.

- Sandos
 
this one really got me stumped , then i changed the ByVals to ByRef ( apart from hOwner and Reserved ) and changed the " shell32.dll " path in the call to IntPtr.Zero
XP requires a pointer rather than a string ( hence the IntPtr.Zero )
here ya go ...
Code:
    Private Declare Function SHChangeIconDialog Lib "shell32" Alias "PickIconDlg" (ByVal hOwner As IntPtr, ByRef szFilename As IntPtr, ByVal Reserved As Integer, ByRef lpIconIndex As Integer) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim intIndex As Integer
        SHChangeIconDialog(Me.Handle, IntPtr.Zero, 0, intIndex)
        MessageBox.Show(intIndex)

    End Sub
 
Its important that you use either the Unicode or Ansi version depending on what OS your on, so on XP you would use the unicode version.

Heres the proper (I think) declarations.

Code:
    Private Declare Unicode Function SHChangeIconDialogW Lib "shell32" Alias "PickIconDlg" (ByVal hOwner As IntPtr, ByVal szFilename As String, ByVal Reserved As Integer, ByRef lpIconIndex As Integer) As Integer
Private Declare Ansi Function SHChangeIconDialogA Lib "shell32" Alias "PickIconDlg" (ByVal hOwner As IntPtr, ByVal szFilename As String, ByVal Reserved As Integer, ByRef lpIconIndex As Integer) As Integer

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim index As Integer
        If System.Environment.OSVersion.Platform = PlatformID.Win32NT Then
            SHChangeIconDialogW(Me.Handle, "C:\Windows\System32\sol.exe", 0, index)
        Else
            SHChangeIconDialogA(Me.Handle, "C:\Windows\System32\sol.exe", 0, index)
        End If
        MessageBox.Show(index.ToString())
    End Sub
 
both SHChangeIconDialogW and SHChangeIconDialogA are using the same function there :-\ ---> " Alias "PickIconDlg" "
the unicode version relies on an Pointer to the string ( StrPtr in vb6 ) rather than the string of the path. so the NT version would not work using SHChangeIconDialogW(Me.Handle, "C:\Windows\System32\sol.exe", 0, index)
it would need a pointer for the path part.
its important that the Alias is taken note of as thats the function within the dll that you are calling.
 
Well SHChangeIconDialogW works perfect for me, and im on XP. But if I try to call the SHChangeIconDialogA then the string gets messed up and i get a message saying it cant find some random characters and it just goes to the default shell32.dll.


Dan
 
Back
Top