Jul 10
It’s easy to extract an application’s own icon in C#:
form.Icon = Icon.ExtractAssociatedIcon( Application.ExecutablePath );
The ExtractAssociatedIcon static method on the Icon class (in System.Drawing) extracts the associated icon from any file. By supplying the Application.ExecutablePath (in System.Windows.Forms), you extract the application’s own icon.
Thanks for that hint! I was really getting worried that there was no easy way to do that in C#!
/nxT
I’m searching for it a lot. Big Thanks!
Good, byt I still have one problem – multiple resolition icons. This seems to be extracting 32×32 icon only, but I want different 16×16 icon (as stretching the 32×32 to 16×16 looks ugly).
I have found a solution using .NET Reflector, some WinApi P/Invoke… well, the thing seems to be, that ExtractAssociatedIcon uses handles, Form.Icon/UpdateIcon uses Icon.ctor(Icon,int,int) to resize the icon to smaller version (to send it by WM_SETICON). This works for resource icons – the Icon.ctor looks for Icon.stream/data, but Icon from ExtractAssociatedIcon does not have the stream, only the handle and thus it’s not working.
hi, i have just encountered the same problem of retriving multiple resolution icons from dll file. how can i control to choose the needed size and color depth in code?