Adding icons to projects

7 replies [Last post]
Offline
Last seen: 15 weeks 3 days ago
Joined: 01/15/2011
Posts:

Just wondering if anybody used compilr to programmatically set a program icon.

The way I'm thinking of doing it is to convert an image to a text file (just a hexdump of the image and add it to a byte array) Upload the textfile into the compilr project. Instantiate some kind of image object around the byte array, and then, hopefully, call some kind of windows api function to register the object as the icon (desktop/runtime).

Question is, is there such an API and what's the name?
Would this also work for a desktop icon? The program won't be activated so probably the os will look into the executable to find some kind of entry point to the image. which means i might have to add some tags around the object?

magius96's picture
Offline
Last seen: 14 weeks 1 day ago
Joined: 04/13/2009
Posts:
Hmm...

I'm sorry, I wish I could be of assistance with this request, but unfortunately I don't know how to do it. I know it can be done, I've just never tried it. I'll do a little research, and if i find a way, then I'll post back here.

----------------------------------------------------------------------------------------------------
"Coding your life, Compiling your dreams, and crashing your future."
Compilr - C# and VB.NET Advisor

tim.speed's picture
Offline
Last seen: 17 hours 48 sec ago
Joined: 02/24/2010
Posts:
As the system is now, the

As the system is now, the data would need to be nested within a class definition and written as a byte array like this:

namespace Demo {
public class ImageData {
public static byte[] Data = {0xff, 0xfe, ...}; // Or however you would like to describe the bytes.
}
}

You can use our upload tool to upload an image file, have your code look for the image file in the execution directory on startup, build your project in the IDE, download the compiled executable then download a zip archive of your project code to get the image on whatever computer you need to.

This is less than ideal, I know :) We will have systems for image resources in the future to embed the image directly into the executable.

-----------------
Tim Speed
Compilr Developer and CTO

Offline
Last seen: 15 weeks 3 days ago
Joined: 01/15/2011
Posts:
I don't think the problem

I don't think the problem lies in getting the image into a byte array. That can be done easily enough with some hexdump tools offline.

My question is more about which APIs to call runtime to register the resulting byte array with windows.

tim.speed's picture
Offline
Last seen: 17 hours 48 sec ago
Joined: 02/24/2010
Posts:
Sorry it took so long to

Sorry it took so long to respond, but there is a tool called reshacker you could use to inject the icon into your application after compiling on compilr as well.
I am not aware of the functions in the windows api that would allow you to do this, but I am sure there is one for setting up for tray icons and forms, if you can find it :)

-----------------
Tim Speed
Compilr Developer and CTO

magius96's picture
Offline
Last seen: 14 weeks 1 day ago
Joined: 04/13/2009
Posts:
Ahah

Found some info:

http://msdn.microsoft.com/en-us/magazine/cc546571.aspx?pr=blog


// Set an icon using code
Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

http://msdn.microsoft.com/en-us/library/system.windows.window.icon.aspx

http://msdn.microsoft.com/en-us/library/ms997538.aspx

http://msdn.microsoft.com/en-us/library/ms648007%28VS.85%29.aspx

But lets keep one thing in mind here...the icon that appears on your desktop while the program is not running can not be set through code. That has to be included in the compiler directives somehow, as it's built into the application during compilation. While you can write AssemblyInfo.cs, Resources.Designer.cs, and Settings.Designer.cs files, I don't know if our compiler here would detect and use them, or even if they would override any such files that may be pre-existing.

I told you I'd come up with something. I always do, I'm like the king of research.

----------------------------------------------------------------------------------------------------
"Coding your life, Compiling your dreams, and crashing your future."
Compilr - C# and VB.NET Advisor

tim.speed's picture
Offline
Last seen: 17 hours 48 sec ago
Joined: 02/24/2010
Posts:
Thanks for the info

Thanks for the info Magius,
our Compiler still does not include resources besides code in its compilation, we hope to remedy this issue within the next few months.
But it should use any .cs files that are defined, so AssemblyInfo.cs, etc...
Should work, although they wont be able to properly reference any resources.

-----------------
Tim Speed
Compilr Developer and CTO

magius96's picture
Offline
Last seen: 14 weeks 1 day ago
Joined: 04/13/2009
Posts:
Umm..

It may not be able to include resources in the build, but if I remember correctly there was a setting that you could place in one of those files to point to an external icon for the desktop icon. I know I've seen it done before, a coworker once did it to use one of the icons included in MoreIcons.dll, instead of drawing one them self, as well as to cut down on the size of the file(since the icon isn't actually built in).

----------------------------------------------------------------------------------------------------
"Coding your life, Compiling your dreams, and crashing your future."
Compilr - C# and VB.NET Advisor