CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 47
  1. #1
    Join Date
    Feb 2009
    Posts
    201

    How do I give my program an icon?

    Hello, all!


    How do I give my program an icon?

    I don't want a .jpg picture in my program folder. How do I code it into the program?


    Cheers,
    realchamp.

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: How do I give my program an icon?

    What kind of program do you have? Runs on Windows, Linux? Is it console, is it window app?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Mar 2009
    Posts
    8

    Re: How do I give my program an icon?

    i also have this question. Im running xcode on a mac, writing a standard c++ program.

  4. #4
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    My program is a console application based on C++. It's for Windows.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How do I give my program an icon?

    Add (insert) an icon as a resource to your project.
    Victor Nijegorodov

  6. #6
    Join Date
    Mar 2009
    Location
    Bulgaria
    Posts
    63

    Re: How do I give my program an icon?

    ... or after building the executable, you can use a program like exescope:
    http://hp.vector.co.jp/authors/VA003525/emysoft.htm#6
    There are a lot of these... if especially this one is licensed or doesn't work for you.

  7. #7
    Join Date
    Mar 2009
    Location
    Riga, Latvia
    Posts
    128

    Re: How do I give my program an icon?

    You should also refer to your compiler. For example in Dev-C++ you could add an icon via Project options.

  8. #8
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    I've trying alot to get it work. I can by now add it as a ressource.

    However, to get it work. What code do I need to use? I've using google for 3 hours now. It seems to make no sence now. I hope you can help me!

    Thanks,
    - realchamp.

  9. #9
    Join Date
    Mar 2008
    Posts
    30

    Re: How do I give my program an icon?

    Here:
    Code:
    1 ICON "icon.ico"
    Save this as .rc file
    You can compile this using windres
    Code:
    windres -i resource.rc -o resource.o
    Then compile it with your main .cpp file
    Code:
    g++ resource.o main.cpp -o main
    If you are using an IDE, just include your .rc file in your project.

  10. #10
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    Ahh I got that. Thank you, I will just try it.

    EIDT: The IDE is that for a console application for Windows?


    That resource.rc, how do I exactly create that? Or is that the file I "extra" included?


    EDIT: The "windres" doesn't work.

    I did:

    Code:
    C:/Plugins/srcds/icon windres -i resource.rc -o resource.o
    Unknown command "windres"
    Last edited by realchamp; March 21st, 2009 at 12:57 PM.

  11. #11
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    Okay, I tryed to include it (#include <resource.rc>)

    I get this error:
    Code:
    syntax error "constant"

  12. #12
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: How do I give my program an icon?

    Hello realchamp

    You don't need to include your resource file.

    To mannually add the icon, (and probablly the easiest way)
    just open up your favorite editor (or notepad) and save it with the .rc extension.
    And do what richard_tominez showed you.
    He put the constant for simplicity, (and used in only one place)
    but you'd normally want to use macro
    Code:
    IDI_MY_ICON DISCARDABLE "icon.ico"
    and make sure to define IDI_MY_ICON somewhere in your program.

    hope this helps~
    Last edited by potatoCode; March 21st, 2009 at 01:50 PM.

  13. #13
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    Okay, I will just try that. Thank you, PotatoCode

    But where do I have to save my resource.rc?

    Right now I have in the same folder as my main(.cpp) program is in.

  14. #14
    Join Date
    Feb 2009
    Posts
    201

    Re: How do I give my program an icon?

    Okay I got the
    Code:
    #define IDI_MY_ICON
    In my program, just after the headers.

    Now what do I do with?:
    Code:
    DI_MY_ICON DISCARDABLE "icon.ico"
    Do I simply just put that in my source code somewhere after int main() { ?


    EDIT: I did that, new errors:
    Code:
    DISCARDABLE : not a command.... blablabla...
    Last edited by realchamp; March 21st, 2009 at 02:18 PM.

  15. #15
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: How do I give my program an icon?

    Okay,

    You forgot the ICON inbetween.
    DISCARDABLE is optional and not required.

    why don't you try this?

    1. Open up a new console project.

    2. Add/Create a blank file

    3. In this new file type
    Code:
    1 ICON "icon.ico"
    4. Save this file as myresource.rc in the root directory of the project

    5. Check your project manager to see the newly added myresource.rc

    6. Build and run

    7. check your exe to see if the icon has been added.

    edit:
    Just in case, you want to replace icon.ico with the actual file name of your icon.
    To create your own icon,
    you can download icon plug-ins for photoshop. (google it)
    Last edited by potatoCode; March 21st, 2009 at 02:44 PM.

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured