locked
Using Default Windows Icons in toolbars RRS feed

  • Question

  • How do I use the default windows icons like save, open, etc. in my toolbars?

    Thanks.
    Saturday, July 7, 2007 7:31 AM

Answers

  • Hi,

     

    Find yourself a copy of iconsext.exe, this little program lets you analyse dlls and exes for icons and then allows you to save them. All you need to do is start and application search for it's icons, save and then use. Great little application.

     

    http://www.nirsoft.net/utils/iconsext.html

    Saturday, July 7, 2007 2:04 PM

All replies

  •  

    Here's somethng that will get you started:

     

    Imports System.Runtime.InteropServices

     

    Public Class Form1

     

        Private Structure SHFILEINFO

            Public hIcon As IntPtr            ' : icon

            Public iIcon As Integer           ' : icondex

            Public dwAttributes As Integer    ' : SFGAO_ flags

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _

            Public szDisplayName As String

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _

            Public szTypeName As String

        End Structure

     

        Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _

                (ByVal pszPath As String, _

                 ByVal dwFileAttributes As Integer, _

                 ByRef psfi As SHFILEINFO, _

                 ByVal cbFileInfo As Integer, _

                 ByVal uFlags As Integer) As IntPtr

     

        Private Const SHGFI_ICON = &H100

        Private Const SHGFI_SMALLICON = &H1

        Private Const SHGFI_LARGEICON = &H0    ' Large icon

        Private nIndex = 0

     

     

     

        Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer

     

     

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

     

            Dim hImgSmall As IntPtr  'The handle to the system image list.

            Dim hImgLarge As IntPtr  'The handle to the system image list.

            Dim fName As String      'The file name to get the icon from.

            Dim shinfo As SHFILEINFO

            shinfo = New SHFILEINFO()

            Dim openFileDialog1 As OpenFileDialog

            openFileDialog1 = New OpenFileDialog()

     

            openFileDialog1.InitialDirectory = "c:\temp\"

            openFileDialog1.Filter = "All files (*.*)|*.*"

            openFileDialog1.FilterIndex = 2

            openFileDialog1.RestoreDirectory = True

     

            ListView1.SmallImageList = ImageList1

            ListView1.LargeImageList = ImageList1

     

            shinfo.szDisplayName = New String(Chr(0), 260)

            shinfo.szTypeName = New String(Chr(0), 80)

     

            If (openFileDialog1.ShowDialog() = DialogResult.OK) Then

                fName = openFileDialog1.FileName

     

                'Use this to get the small icon.

                hImgSmall = SHGetFileInfo(fName, 0, shinfo, _

                            Marshal.SizeOf(shinfo), _

                            SHGFI_ICON Or SHGFI_SMALLICON)

     

                'Use this to get the large icon.

                'hImgLarge = SHGetFileInfo(fName, 0,

                'ref shinfo, (uint)Marshal.SizeOf(shinfo),

                'SHGFI_ICON | SHGFI_LARGEICON);

     

                'The icon is returned in the hIcon member of the

                'shinfo struct.

                Dim myIcon As System.Drawing.Icon

                myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

     

                ImageList1.Images.Add(myIcon)       'Add icon to

                'imageList.

     

                ListView1.Items.Add(fName, nIndex)  'Add file name and

                'icon to listview.

                nIndex = nIndex + 1

            End If

     

        End Sub

    End Class

    If I remember correctly it stored the icons in an imagelist. Be sure to set the imagelist's color depth to maximum.

    Saturday, July 7, 2007 8:11 AM
  •  

    Here's somethng that will get you started:

     

    Imports System.Runtime.InteropServices

     

    Public Class Form1

     

        Private Structure SHFILEINFO

            Public hIcon As IntPtr            ' : icon

            Public iIcon As Integer           ' : icondex

            Public dwAttributes As Integer    ' : SFGAO_ flags

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _

            Public szDisplayName As String

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _

            Public szTypeName As String

        End Structure

     

        Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _

                (ByVal pszPath As String, _

                 ByVal dwFileAttributes As Integer, _

                 ByRef psfi As SHFILEINFO, _

                 ByVal cbFileInfo As Integer, _

                 ByVal uFlags As Integer) As IntPtr

     

        Private Const SHGFI_ICON = &H100

        Private Const SHGFI_SMALLICON = &H1

        Private Const SHGFI_LARGEICON = &H0    ' Large icon

        Private nIndex = 0

     

     

     

        Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer

     

     

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

     

            Dim hImgSmall As IntPtr  'The handle to the system image list.

            Dim hImgLarge As IntPtr  'The handle to the system image list.

            Dim fName As String      'The file name to get the icon from.

            Dim shinfo As SHFILEINFO

            shinfo = New SHFILEINFO()

            Dim openFileDialog1 As OpenFileDialog

            openFileDialog1 = New OpenFileDialog()

     

            openFileDialog1.InitialDirectory = "c:\temp\"

            openFileDialog1.Filter = "All files (*.*)|*.*"

            openFileDialog1.FilterIndex = 2

            openFileDialog1.RestoreDirectory = True

     

            ListView1.SmallImageList = ImageList1

            ListView1.LargeImageList = ImageList1

     

            shinfo.szDisplayName = New String(Chr(0), 260)

            shinfo.szTypeName = New String(Chr(0), 80)

     

            If (openFileDialog1.ShowDialog() = DialogResult.OK) Then

                fName = openFileDialog1.FileName

     

                'Use this to get the small icon.

                hImgSmall = SHGetFileInfo(fName, 0, shinfo, _

                            Marshal.SizeOf(shinfo), _

                            SHGFI_ICON Or SHGFI_SMALLICON)

     

                'Use this to get the large icon.

                'hImgLarge = SHGetFileInfo(fName, 0,

                'ref shinfo, (uint)Marshal.SizeOf(shinfo),

                'SHGFI_ICON | SHGFI_LARGEICON);

     

                'The icon is returned in the hIcon member of the

                'shinfo struct.

                Dim myIcon As System.Drawing.Icon

                myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

     

                ImageList1.Images.Add(myIcon)       'Add icon to

                'imageList.

     

                ListView1.Items.Add(fName, nIndex)  'Add file name and

                'icon to listview.

                nIndex = nIndex + 1

            End If

     

        End Sub

    End Class

    If I remember correctly it stored the icons in an imagelist. Be sure to set the imagelist's color depth to maximum.

    Saturday, July 7, 2007 8:12 AM
  •  

    Here's somethng that will get you started:

     

    Imports System.Runtime.InteropServices

     

    Public Class Form1

     

        Private Structure SHFILEINFO

            Public hIcon As IntPtr            ' : icon

            Public iIcon As Integer           ' : icondex

            Public dwAttributes As Integer    ' : SFGAO_ flags

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _

            Public szDisplayName As String

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _

            Public szTypeName As String

        End Structure

     

        Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _

                (ByVal pszPath As String, _

                 ByVal dwFileAttributes As Integer, _

                 ByRef psfi As SHFILEINFO, _

                 ByVal cbFileInfo As Integer, _

                 ByVal uFlags As Integer) As IntPtr

     

        Private Const SHGFI_ICON = &H100

        Private Const SHGFI_SMALLICON = &H1

        Private Const SHGFI_LARGEICON = &H0    ' Large icon

        Private nIndex = 0

     

     

     

        Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer

     

     

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

     

            Dim hImgSmall As IntPtr  'The handle to the system image list.

            Dim hImgLarge As IntPtr  'The handle to the system image list.

            Dim fName As String      'The file name to get the icon from.

            Dim shinfo As SHFILEINFO

            shinfo = New SHFILEINFO()

            Dim openFileDialog1 As OpenFileDialog

            openFileDialog1 = New OpenFileDialog()

     

            openFileDialog1.InitialDirectory = "c:\temp\"

            openFileDialog1.Filter = "All files (*.*)|*.*"

            openFileDialog1.FilterIndex = 2

            openFileDialog1.RestoreDirectory = True

     

            ListView1.SmallImageList = ImageList1

            ListView1.LargeImageList = ImageList1

     

            shinfo.szDisplayName = New String(Chr(0), 260)

            shinfo.szTypeName = New String(Chr(0), 80)

     

            If (openFileDialog1.ShowDialog() = DialogResult.OK) Then

                fName = openFileDialog1.FileName

     

                'Use this to get the small icon.

                hImgSmall = SHGetFileInfo(fName, 0, shinfo, _

                            Marshal.SizeOf(shinfo), _

                            SHGFI_ICON Or SHGFI_SMALLICON)

     

                'Use this to get the large icon.

                'hImgLarge = SHGetFileInfo(fName, 0,

                'ref shinfo, (uint)Marshal.SizeOf(shinfo),

                'SHGFI_ICON | SHGFI_LARGEICON);

     

                'The icon is returned in the hIcon member of the

                'shinfo struct.

                Dim myIcon As System.Drawing.Icon

                myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

     

                ImageList1.Images.Add(myIcon)       'Add icon to

                'imageList.

     

                ListView1.Items.Add(fName, nIndex)  'Add file name and

                'icon to listview.

                nIndex = nIndex + 1

            End If

     

        End Sub

    End Class

    If I remember correctly it stored the icons in an imagelist. Be sure to set the imagelist's color depth to maximum.

    Saturday, July 7, 2007 8:12 AM
  • I don't want file icons, I want icons like save, etc.
    Saturday, July 7, 2007 8:22 AM
  • Hi,

     

    Find yourself a copy of iconsext.exe, this little program lets you analyse dlls and exes for icons and then allows you to save them. All you need to do is start and application search for it's icons, save and then use. Great little application.

     

    http://www.nirsoft.net/utils/iconsext.html

    Saturday, July 7, 2007 2:04 PM