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.
Printable View
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.
What kind of program do you have? Runs on Windows, Linux? Is it console, is it window app?
i also have this question. Im running xcode on a mac, writing a standard c++ program.
My program is a console application based on C++. It's for Windows.
Add (insert) an icon as a resource to your project.
... 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.
You should also refer to your compiler. For example in Dev-C++ you could add an icon via Project options.
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.
Here:
Save this as .rc fileCode:1 ICON "icon.ico"
You can compile this using windres
Then compile it with your main .cpp fileCode:windres -i resource.rc -o resource.o
If you are using an IDE, just include your .rc file in your project.Code:g++ resource.o main.cpp -o main
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:
Unknown command "windres"Code:C:/Plugins/srcds/icon windres -i resource.rc -o resource.o
Okay, I tryed to include it (#include <resource.rc>)
I get this error:
Code:syntax error "constant"
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
and make sure to define IDI_MY_ICON somewhere in your program.Code:IDI_MY_ICON DISCARDABLE "icon.ico"
hope this helps~
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.
Okay I got theIn my program, just after the headers.Code:#define IDI_MY_ICON
Now what do I do with?:Do I simply just put that in my source code somewhere after int main() { ?Code:DI_MY_ICON DISCARDABLE "icon.ico"
EDIT: I did that, new errors:
Code:DISCARDABLE : not a command.... blablabla...
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
4. Save this file as myresource.rc in the root directory of the projectCode:1 ICON "icon.ico"
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) :)
I will try that, thank you so much!
But at 1.; Do I have to create a new .cpp file? And then in the solution explorer, I add the .rc file?
Or just create a blank .rc file with notepad and add 3. into it?
I don't use the "project" stuff.
I just use "New File" and then I set it to .cpp and then I start coding.
Sure you can do that.
A resource file is just a text file with .rc extension.
VC++ 2008 express edition doesn't have a resource editor,
but that doesn't mean you can manage your resources :)
in all, you need a total of three files.
1. whatever.cpp
2. whateverName.rc
3. whateverIcon.ico
unless you can follow richard_tominez's answer on how to manually bind the resource file
to the exe file,
your best chance is to let your project manager (or solution manager) to do the job.
Hehe, you might want to start using it because you will eventually need it. ;)Quote:
I don't use the "project" stuff.
For example, NetBeans (another cool IDE) PM checks code file dependancy by refactoring,
something you can definitely appreciate.
Okay... I tryed both ways. The one of them gave me 78 errors. (Using the project).
I tryed the one with compiling, just getting unknown command "windres".
I wanna use the windres.
However with this in my code:
And this in my icon.rc:Code:#define MY_ICON
using namespace std;
int main()
{
MY_ICON ICON "icon.ico";
bool quit = false;
while (! quit)
{
Code:ICON "icon.ico"
Both my icon.ico and .rc are in the same folder as my main .cpp is.
However when I use the 1 you both set, I get errors. Without it, no errors at all. But the ICON didn't work on my program.
Great, stay on this track. :)
this is how the rest of the files might look like
main.cppmyresource.rcCode:#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
Build your project all together.Code:101 ICON "icon.ico"
Let me know how it goes
What do you exactly mean? Also, when I don't try to add any "icon" stuff, the program doesn't give me errors or so.
Also if you would like to, I can give you TeamViewer 4 access. Then you can see it with your own eyes.
Or we can just chat over MSN or Steam.
Only if you want.
(I hope I didn't break any forum rules there?)
I think we can still solve your problem here.
(and for those who might need the same help later on)
you followed everything I told you but it still didn't work?
Hm, that's odd.
What IDE are you using?
Okay, that's fine.
However, I'm not sure what you mean about "IDE?".. I haven't found out of what that is yet. Only guessing.
windres is one of the utilities of Mingw package.
To compile your .rc file in command-line using cmd shell:
where:Code:c:\mingw\bin> windres -i c:\resource.rc -o c:\resource.o
c:\mingw\bin> is the directory where windres is
windres is the program itself
c:\resource.rc is the input file in C:\ directory
c:\resource.o is the outpuit file in C:\ directory
The commands I gave previously are for MSYS.
Ohh okay.
Is the folder on my c drive a standard one? (mingw?) Or do I have to DL something?
Okay, I tryed setting it up as you created it. It works. But I don't have any resource.o file.
I ran it in a batch script.
Didn't work. I'm getting invalid directory or no files. Even though my files are in that directory.Code:c:\mingw\bin> windres -i c:\Plugins\srcds\resource.rc -o c:\Plugins\srcds\resource.o
(It wouldn't let me save it into c:\srcds.
However I get a new file: windres. But it's a empty and it's only a "file" (none of these .dll, .exe, .bat extensions)
Rather than ask in each your post just use google. The first link does explain it. :cool:
http://www.google.com/search?sourcei...,GGLJ:en&q=ide
[QUOTE=realchamp;1825171ps. Anyone there can help me with this?[/QUOTE]Help you with what?
What is the current state of your problem?
What IDE (VC++ 6,0, VS2002/2003/2005/2008, ...) are you using?
Try it again. I should also noted that c:\mingw\bin> is the working directory.
1. Run cmd from the start menu
2. Change the current directory in the bin folder in your mingw installation
3. Run windres like this:Code:cd c:\mingw\bin
If still doesn't work, I suggest, you pray to St. Anthony of Padua that you may found the answer.Code:windres -i c:\resource.rc -o c:\resource.o
Well thanks, once agian richard_tominez.
But, when I do that. The cd c:\mingw\bin
Gives me an invalid directory. Like it doesn't exits. However I can't see it either. (When I open up my C folder)
I'm on Windows Vista 32BIT: Home Premium, if that should do any different.'
EDIT: I used google, now I'm downloading that mingw. :)
Okay, now I got it installed. It doesn't say unknow command anymore.
But when I try to compile it, I get these errors:
In my C:\Plugins\srcds\ folder I have these files:Code:C:\Plugins\srcds>cd c:\mingw\bin
c:\MinGW\bin>windres -i C:\Plugins\srcds\resource.rc -o C:\Plugins\srcds\resourc
e.o
C:\Plugins\srcds\resource.rc:1:24: warning: no newline at end of file
windres: can't open icon file `resource.ico': No such file or directory
c:\MinGW\bin>pause
resource.ico
resource.rc with this data:
resource.bat with this data:Code:101 ICON "resource.ico"
And I do also have my main program.Code:cd c:\mingw\bin
windres -i C:\Plugins\srcds\resource.rc -o C:\Plugins\srcds\resource.o
pause
EDIT:
Now I got the resource.o file.
Code:C:\Plugins\srcds>cd c:/mingw/bin
c:\MinGW\bin>g++ resource.o c:/Plugins/srcds/srcds_beta.cpp -o main
c:/Plugins/srcds/srcds_beta.cpp: In function `int main()':
c:/Plugins/srcds/srcds_beta.cpp:88: warning: `_sleep' is deprecated (declared at
../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:88: warning: `_sleep' is deprecated (declared at
../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:213: warning: `_sleep' is deprecated (declared a
t ../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:213: warning: `_sleep' is deprecated (declared a
t ../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:223:2: warning: no newline at end of file
c:\MinGW\bin>pause
Why now this? :(
Please someone help me!
I compiled my srcds_beta.cpp in VC++ 2008: Express Edition.
I didn't get any errors.
And now this:
Code:
C:\Plugins\srcds>cd c:/mingw/bin
c:\MinGW\bin>g++ resource.o c:/Plugins/srcds/srcds_beta.cpp -o c:\Plugin\srcds\s
rcds_beta.exe
c:/Plugins/srcds/srcds_beta.cpp: In function `int main()':
c:/Plugins/srcds/srcds_beta.cpp:88: warning: `_sleep' is deprecated (declared at
../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:88: warning: `_sleep' is deprecated (declared at
../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:213: warning: `_sleep' is deprecated (declared a
t ../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:213: warning: `_sleep' is deprecated (declared a
t ../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:404)
c:/Plugins/srcds/srcds_beta.cpp:223:2: warning: no newline at end of file
..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot open output file
c:\Plugin\srcds\srcds_beta.exe: No such file or directory
collect2: ld returned 1 exit status
c:\MinGW\bin>pause
Someone please help. I wanna get this to work! :)
Hehe, tell me if you need more information!
_sleep function is obsolete. Try including windows.h to use Sleep function as a replacement to it.
I already included it. :(
When I run my own program in VC++ 2008: Express Version, it works perfect. No errors at all! (with _sleep(2000))
Here's my headers:
Code:#include <iostream>
#include <fstream>
#include <cstring>
#include <stdlib.h>
#include <string>
#include <direct.h>
#include <Windows.h>
#include <WinBase.h>
Windows.h is different from windows.h.Code:#include <iostream>
#include <fstream>
#include <cstring>
#include <stdlib.h>
#include <string>
#include <direct.h>
#include <Windows.h>
#include <WinBase.h>
Anyways, your problem is how to give your program an icon. The important matter is you know the steps to give your program an icon. Create a simple Hello World program with your resource.o and see what you got.
Now my program doesn't know "cout".
Here's my code:
Code:// hello_world.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World!";
}
And error:
I included the <iostream> in the main file. Didn't work.Code:1>------ Build started: Project: hello_world, Configuration: Debug Win32 ------
1>Compiling...
1>hello_world.cpp
1>c:\plugins\srcds\beta\hello_world\hello_world\hello_world.cpp(9) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Plugins\srcds\beta\hello_world\hello_world\Debug\BuildLog.htm"
1>hello_world - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also added the resource.o to resources.
It said "unknown rules" - I just ran throught and it worked.(I hope)
cout is a member of the std namespace. To use it:
Code:std::cout << "Hello World!";
Hello, it works! No errors on compiling.
However when I use the project manager I don't get any .exe file? :/
So I can't really check if it works :(
No errors on compiling? How about on linking?
What do you mean by "linking?"
Don't you know what "linking" (or Link) is? :confused:
Very bad! :eek: :thumbd:
Can't you use Internet search? :confused:
Well, checking out some of these sites will be a good start for you:
http://www.google.de/search?hl=en&rl...nk&btnG=Search
I know what a "link" is.
Like a link to Google.
But I don't understand what he means with "on linking?"
Building an executable is done in two steps.
Compiling takes your source code and converts it into low level instructions for the computer. Those are your object .obj files.
The linker takes your .obj and library files and converts them into the executable file.
Your program may compile but not link.
Ahh..
Would this "link" my program?:
I use Microsoft Visual Studio 2008: Express Editon.
And I use cl -EHsc srcds_beta.cpp for compiling.
Output:
srcds_beta.exe
srcds_beta.obj