Archive for February, 2008

NativeFileTypeViewer : FileIconImageConverter – Convert a filename to the file system icon.

I’ve recently been creating more desktop applications and I often needed to print out the system icons for standard files.  In the past I had used Photoshop to crop out the icons and I ended up only supportting a limited number of file icons.  And as I was writing this post I also found a shell32 tatic  used to create ImageLists in WinForms.

In order to load the system file icons and descriptions for my WPF applications, I built this Binding Converter.  The FileIconImageConverter.cs file is an IValueConverter that accepts  a filename or full file path.  The Converter supports caching and both 32-pixel and 16-pixel icons.  With the exception of the cache checking functionality, this converter has 4 main parts. First it creates a blank 0kb text file the the same extension as the source filename.  Second it loads a SHFILEINFO Struct using Win32.SHGetFileInfo and creates an Icon from the handle. Third it creates Bitmap from the Icon and saves it to a MemoryStream as a PNG.  Finally it loads the ImageSource using a PngBitmapDecoder from the previous Memory Stream.

I would love to give credit to Atul Gupta’s Blog, which help me out a lot with this.  I haven’t tried it in Silverlight, please let me know if you try it.  Please see my website for the full code.

http://www.bendewey.com/code/FilenameIconImageConverter.html

This little application, called the NativeFileTypeViewer (source code), loads a directory and converts the filenames into the filename descriptions and the file icon, to demonstrate the use of the binding converters.

Native FileType Viewer

Advertisements

Swoosh Button

I created this little swoosh button, as I call it, as my main button design for most of my apps. There are three colors for now but it can easily be adapted to support multiple more. There is a standard blue color, a red color (i used for the cancel buttons), and a green color (I used for the OK and Next Buttons) . I also think the button looks really good with all caps text.

I keep trying to come up with a good way to pass the color in without creating a custom control. If anyone has any thought please feel free to share.

Enjoy

SwooshButtonBlueSwoosh

Usage

<Button Width=”60″ x:Name=”browse” Style=”{StaticResource SwooshButton}”>Browse</Button>

Code

http://www.bendewey.name/code/swooshButton.html

My First Blog Post

I’m Ben Dewey, this is my first blog post.  I am hoping to post code samples and discussions on cool .NET controls.  I will be posting code in my free time which is fairly limited. 

My brother is a big open source guy and this blog is going to be my contribution to the open source world.  WPF has some great features that allow programmers to reuse control templates.  If I can save some other programmers time and effort than I’ll be happy.

Comments are always welcome.  I’ll try to respond as quickly as possible, but please be patient.


What else am I doing?

StackOverflow Facebook Twitter LinkedIn Live

Twitter

Pages

February 2008
M T W T F S S
    Jul »
 123
45678910
11121314151617
18192021222324
2526272829