Home > Resources

Resources

Online C# code beautifiers

2011-02-09 ( Categories: .NET > Software Engineering )

What online C# code beautifier could you use?

In many places have I read that the best (or perhaps only) tool to format C# as HTML code that highlights syntax is the Manoli C# formatter. True, it has successfully highlighted text and offers several options, but it does not highlight types. For this reason I have been looking for an alternative and I've found Format my C# code page that although offers less options, it highlights types - as they advertize it, Yes! It can recognize Types!. It is not perfect as you may see in the code snippets I post, but it's good enough. And despite the fact I need to verify every code it formats (since I noticed this tool removed two dots in code), I prefer it to the most popular tool that Google returns.

Extracting icons from within .NET applications

2011-02-09 ( Categories: .NET > WinAPI )

The problem seemed quite simple: extract largest available icon of current (or any other) application. The first approach used a function that ITLN Utils already had contained: extracting icons from applications using ExtractIconEx function. Soon it turned out that this method greatly fails, and many variations of LoadImage. Finally the problem has been solved, after having read tons of documentation, samples and projects.

NOTE: There are downloads at the end of the article.

First approach

At first, ExtractIconEx method seemed good enough. This method returns small or large icons from a file. I used a sample from PInvoke.NET that read:

/// <summary>
/// Returns an icon of given application.
/// </summary>
/// <param name="file">Path to the application that contains icons.</param>
/// <param name="large">Whether to return large or small icon.</param>
/// <returns>Application's icon.</returns>
public static Icon GetIconFromExe(string file, bool large) {
    int readIconCount = 0;
    IntPtr[] hDummy = new IntPtr[1] { IntPtr.Zero };
    IntPtr[] hIconEx = new IntPtr[1] { IntPtr.Zero };


    try {
        if (large)
            readIconCount = WinAPI.ExtractIconEx(file, 0, hIconEx, hDummy, 1);
        else
            readIconCount = WinAPI.ExtractIconEx(file, 0, hDummy, hIconEx, 1);


        if (readIconCount > 0 && hIconEx[0] != IntPtr.Zero) {
            // GET FIRST EXTRACTED ICON
            Icon extractedIcon = (Icon)Icon.FromHandle(hIconEx[0]).Clone();


            return extractedIcon;
        } else // NO ICONS READ
            return null;

    } finally {

        // RELEASE RESOURCES
        foreach (IntPtr ptr in hIconEx)
            if (ptr != IntPtr.Zero)
                WinAPI.DestroyIcon(ptr);

        foreach (IntPtr ptr in hDummy)
            if (ptr != IntPtr.Zero)
                WinAPI.DestroyIcon(ptr);
    }
}

This method correctly returned both small (16x16) and "large" (32x32) application icons. Because method ExtractIconEx can return amount of icons and several icons, I created such a simple function:

Read more >

Icon caching and oddity of choosing sizes of icons and applications preview by Vista

2011-02-09 ( Categories: Operating System > Windows )

It is quite possible to encounter weird obstacles while creating and applying icons for applications in Windows Vista, and possibly other, systems. One thing is icon caching which unables you to see immediate changes to the files, and the other is misleading method of displaying icon in Explorer. I'll describe the problems and possible solutions or walkarounds.

NOTE: There are downloads at the end of the article.

Icon caching

If you have edited an icon file or changed an application's icon, and you can't see the change in Explorer, you may need to clear cache of icons. You may find more information in this newsgroup thread. You can find there that in such a case you need to manually delete the icon cache file (IconCache.db) and restart Explorer:

Read more >