Click here to Skip to main content
15,884,237 members
Articles / Desktop Programming / Windows Forms

i00 Spell Check and Control Extensions - No Third Party Components Required!

Rate me:
Please Sign up or sign in to vote.
4.95/5 (117 votes)
11 Jan 2014Ms-PL16 min read 1.3M   21   266  
Simple to use, open source Spell Checker for .NET
'This code was origionaly taken from http://vbcity.com/forums/t/38841.aspx

Imports System.Drawing
Imports System.Runtime.InteropServices

Public Class IconExtraction

    '=====================================================================================
    ' Enumerations
    '=====================================================================================
    <Flags()> Private Enum SHGFI
        SmallIcon = &H1
        LargeIcon = &H0
        Icon = &H100
        DisplayName = &H200
        Typename = &H400
        SysIconIndex = &H4000
        UseFileAttributes = &H10
    End Enum

    Public Enum IconSize
        SmallIcon = 1
        LargeIcon = 0
    End Enum

    '=====================================================================================
    ' Structures
    '=====================================================================================
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure SHFILEINFO
        Public hIcon As IntPtr
        Public iIcon As Integer
        Public dwAttributes As Integer
        <MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> Public szDisplayName As String
        <MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> Public szTypeName As String

        Public Sub New(ByVal B As Boolean)
            hIcon = IntPtr.Zero
            iIcon = 0
            dwAttributes = 0
            szDisplayName = vbNullString
            szTypeName = vbNullString
        End Sub
    End Structure

    '=====================================================================================
    ' API Calls
    '=====================================================================================
    Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlagsn As Integer) As Integer

    '=====================================================================================
    ' Functions and Procedures...
    '=====================================================================================
    Public Shared Function GetDefaultIcon(ByVal Path As String, Optional ByVal IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath As String = "") As Icon
        Dim info As New SHFILEINFO(True)
        Dim cbSizeInfo As Integer = Marshal.SizeOf(info)
        Dim flags As Integer = SHGFI.Icon Or SHGFI.UseFileAttributes
        flags = flags + IconSize
        SHGetFileInfo(Path, 256, info, cbSizeInfo, flags)
        GetDefaultIcon = Icon.FromHandle(info.hIcon)
        If SaveIconPath <> "" Then
            Dim FileStream As New IO.FileStream(SaveIconPath, IO.FileMode.Create)
            GetDefaultIcon.Save(FileStream)
            FileStream.Close()
        End If
    End Function      'GetDefaultIcon(ByVal Path As String, Optional ByVal IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath As String = "") As Icon
    '=====================================================================================
    Public Shared Function ImageToIcon(ByVal SourceImage As Image) As Icon
        ' converts an image into an icon
        Dim TempBitmap As New Bitmap(SourceImage)
        ImageToIcon = Icon.FromHandle(TempBitmap.GetHicon())
        TempBitmap.Dispose()
    End Function      'ImageToIcon(ByVal SourceImage As Image) As Icon
    '=====================================================================================

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
i00
Software Developer (Senior) i00 Productions
Australia Australia
I hope you enjoy my code. It's yours to use for free, but if you do wish to say thank you then a donation is always appreciated.
You can donate here.

Comments and Discussions