C++/Help on a basic level: resource files
Me and my programming teacher in high school is trying to learn more about .rc files, and how to create them using Microsoft Visual Studio 6.0
We figured that the best way to handle and use .rc files at our basic level would be to create them using the graphical resource editor. But we haven't figured out how to do this from scratch, how can we create a completely new .rc file using the graphical editor in an easy way? We've already come to the conclusion that you can't just create an empty C++ source code file and just name it .rc
So, how to do? Help us please, then we can teach the other students :)
First I must point out that this is _not_ a C++ question. It is a question about how to use a specific product and you should refer to the documentation that came with that product. Unfortunately as VC6 is now 3 revisions behind the current VC release the available documentation in the more recent MSDN library versions is very limited (meaning I no longer have it to hand).
Anyhow you are lucky that I still have VC6 installed on a machine so could play around a bit.
The first option is to create a project type that creates a .rc file. However these may be automatically updated by the IDE in ways you do not want, but as you are using the resource editors this is probably not too much of a problem, at least not at first. Projects types include a Win32 application (note: not a console application), selecting to have a hello world application and MFC applications.
The second method is to select the menu items Insert | Resource and select a resource type. The editor for that resource type will open as well as the resource file items tree view pane. You will note that it has the name script1 or similar. If you save the file it will suggest the name script1.rc, which you can change to the name of your choice.
The third option is to just create a new text file and name it with a .rc extension. Add a comment to the file e.g.
// Resource script
Save it and reopen it. Like other code files resource script files are simply text files. However the VC6 IDE will try to open them in the resource editor (AKA App Studio) which is what it does when you reopen the file. You should get a blank resource file tree view into which you can insert or import resources. When you save your resources you will be asked to confirm overwriting the previous contents. Answer yes. Note if you do _not_ add some text (a space or blank line should be enough) then VC6 will create the resources as _binary_ (compiled) resources rather than a script with textual descriptions. You can tell as the resources will have numbers (e.g. 101) rather then names (e.g. IDD_DIALOG1). This will then cause problems loading it into a project.
For the second and third options the file created will not be part of any project (unless you added a file using Project | Add | New), so you will have to add the .rc file to your project.
When you add resources to your .rc file and save them VC6 should create a header file called resource.h which contains #define macro definitions for the named resources to their resource values if you do not already have such a header. You should add this file to you project if it is not already. Note that if you try working with 2 .rc files in the same directory then both will use the resource.h file. Hopefully the IDE should warn you if one already existed. This file is the link between your Windows code and the resource script - they both include this file to ensure they both use the same resource value definitions. Note that the resource compiler does not understand more modern ways to define constant integers such as
unsigned short const IDD_DIALOG1(101);
As mentioned if you open a .rc file VC6 will automatically open it using the resource editing view. You can override this behaviour should you wish by selecting menu items File | Open (or equivalent), select the .rc file in the open dialog and (the important bit) select Text from the Open as: drop down list.
Finally, a hint from my experience with VC6's resource editing capabilities. It works very well so long as you play by VC6's rules. If you do not then you and it will have words! If changes you make outside of editing in the resource editor - such as re-numbering the resources in resource.h for example - seem to revert back when next you enter the IDE controlled editing then try (without VC6 running) deleting the rcfilenamestem.aps file. As far as I can tell this is where the VC6 IDE stores information about the previous project resource editing session. Also take care to note the special sections VC6 adds to the .rc file and resource.h file if ignoring the warning comment at the top of the file and editing VC6 maintained .rc files by hand. I and many others have spent a lot of time trying to bend VC6 to our will with regard to resource scripts and definitions!