locked
Embedding Icons into Assemblies RRS feed

  • Question

  • Hello -

    I am needing to add icons to my application and I would like to do it by embedding the icons into the assembly itself. I have searched the internet and found articles describing how to do this. They say to add the .ico file into my project and then set the BuildAction property to  "Embedded Resource". I am using Visuall C++ .NET 2003 and do not find this BuildAction property in the Properties Window or Property Pages associated with the .ico file. Can anyone tell my the best way to embedd icons into an assembly using Visual C++ .NET 2003? Also, if anyone has a code snippet of how to load the icon once I have managed to embedd it that would be appreciated too. Thanks -

    Samy
    Wednesday, March 1, 2006 8:47 PM

Answers

  • Hi Samy,

    You can use the Resource Editor available for VC to add new icons to the project. They will get embedded by default in the resulting binary.

    Depending on what are you using in your app you can load the icon by:

    HICON hIcon = AfxGetApp()->LoadIcon( IDI_YOURICONID ); //MFC

    HICON hIcon = LoadIcon( hInstance, lpIconName ); //Native

    Icon ico = Icon.FromHandle( LoadIcon (hInstance, lpIconName ); //Managed

    For the managed version, you would have to use interop to call LoadIcon.
    For more indebt info about icons in windows try this.

    Hope this helps,
    Marian Luparu
    Visual C++ IDE

    Monday, March 6, 2006 12:24 AM

All replies

  •  Samyag1 wrote:
    Hello -

    I am needing to add icons to my application and I would like to do it by embedding the icons into the assembly itself. I have searched the internet and found articles describing how to do this. They say to add the .ico file into my project and then set the BuildAction property to  "Embedded Resource". I am using Visuall C++ .NET 2003 and do not find this BuildAction property in the Properties Window or Property Pages associated with the .ico file. Can anyone tell my the best way to embedd icons into an assembly using Visual C++ .NET 2003? Also, if anyone has a code snippet of how to load the icon once I have managed to embedd it that would be appreciated too. Thanks -

    Samy

    See http://www.codeproject.com/csharp/trayiconmenu01.asp

    I wrote that a good while ago and it's VS.NET 2003/C# based. I guess the same should work for a VS.NET 2003/MC++ project too.

    Thursday, March 2, 2006 12:08 AM
  • Nishant -

    Thanks for the reply. This is the solution that I've found at several other locations on the web. The problem for me is that when I right-click the .ico file in the solution explorer and select properties I don't see the "Build Action" Property. I don't know if that's a difference between Visual Studio for C# and C++, or if there's some Option I have set that is hiding this Property. Any ideas?

    Thanks -

    Samy
    Thursday, March 2, 2006 12:50 AM
  • Hi Samy,

    You can use the Resource Editor available for VC to add new icons to the project. They will get embedded by default in the resulting binary.

    Depending on what are you using in your app you can load the icon by:

    HICON hIcon = AfxGetApp()->LoadIcon( IDI_YOURICONID ); //MFC

    HICON hIcon = LoadIcon( hInstance, lpIconName ); //Native

    Icon ico = Icon.FromHandle( LoadIcon (hInstance, lpIconName ); //Managed

    For the managed version, you would have to use interop to call LoadIcon.
    For more indebt info about icons in windows try this.

    Hope this helps,
    Marian Luparu
    Visual C++ IDE

    Monday, March 6, 2006 12:24 AM