Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Embedded icons in .exe
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01502999
Message ID:
01503327
Views:
24
>>>>>>>>>Hi All, I've added several icons as embedded resources into my exe using the resource editor, however if I right click a shortcut to my.exe and select change icon / browse to my.exe - only the icon I set in the icon and manifest tab of the projects' properties tab is shown ? any ideas ?
>>>>>>>>
>>>>>>>>http://www.codeproject.com/KB/dotnet/embedmultipleiconsdotnet.aspx
>>>>>>>
>>>>>>>Thanks Viv, I actually read that article ( obviously not properly ! ) and couldn't get it to work - I was looking in the wrong place for Properties ! thanks again it works perfectly
>>>>>>
>>>>>>Sorry. Just noticed that the link was based on VS2005 but sounds like you found the right place to add the resource file to the app...
>>>>>
>>>>>Hi Viv, having successfuly created Resource.res - do you know how to extract an icon / cursor from one ? I've googled away but can't find much of use
>>>>
>>>>In VS just open the .res file (using File/Open)
>>>>Locate the icon that you want to extract.
>>>>Right Click , choose Export.....
>>>
>>>Hi Viv, sorry I didn't word my question very well - what I meant to ask was - now that I've embedded some icons / cursors / images etc... - how can I access them at runtime - I basically want to give certain groups of users different icons / background images etc... at runtime
>>
>>I don't think there's a simple way of retrieving from the Win32 resource file but if you add the icons to the embedded resources you could just use:
this.Icon = (Icon)WindowsFormsApplication1.Properties.Resources.ResourceManager.GetObject("RESOURCENAME");
(adjust namespace to suit)
>
>That's ok for icons but I don't think you can add cursors as embedded resources - here's what I have so far ( it ain't pretty but it works )
>
>
>[DllImport("user32.dll")]
>public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
>
>this.Cursor = new Cursor(LoadCursor(Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),119));
>
>
>
>where 119 is my resource id ( just being silly putting it all in one statement )

Looks good (and is probably your best bet) but, for the record, you can use the embedded resource option. In the designer just choose Add Resource/Add Existing File... and select the Cursor file. You can then retrieve it as a byte[] so:
byte[] b = (byte[]) WindowsFormsApplication1.Properties.Resources.ResourceManager.GetObject("MyCursor");
Cursor c = new Cursor(new MemoryStream(b));
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform