You are here:

C++/Help on a basic level: resource files

Advertisement


Question
Hi!

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 :)

//Hannes

Answer
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!

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ralph McArdell

Expertise

I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.

Experience

My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.

Education/Credentials

©2016 About.com. All rights reserved.