Thread: Resource Files

  1. #1
    Unregistered
    Guest

    Resource Files

    I was just looking at a Windows programming example in VC++. Then I saw a "resource file". I looked in it and found some "visual" components that the program used. I thought you programmed in the visual part of a Windows program? Am I wrong? I thought that menu (for example) was programmed by hand. How are these visual components made? Thanks.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You can hard code some things or use a resource editor IE Menus....

    Resource editors create a .rc script as a text file. The file doesn't actually contain the visual components, its just a compiler script that describes how to load them.

  3. #3
    Unregistered
    Guest
    I don't understand. So, you do create the controls (dialogs, menus, etc.) with pure code (text) in a text-editor? You don't create them visually (what I mean is by a click-and-drag method), but you create them with raw code? Thanks.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You can create them with a text editor and save them as a .rc file like;

    Code:
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        POPUP "Connection"
        BEGIN
            MENUITEM "Connect",                     ID_CONN
            MENUITEM "Disconnect",                  ID_DIS
            MENUITEM SEPARATOR
            MENUITEM "Exit",                        ID_EXIT
        END
    END
    This details a menu that you can call LoadMenu() on. If you use the resource editor with say VC++6, you can build this component graphically but it will still save it as the script you see above.

    You can also create a menu directly in your code with the CreateMenu() function.

  5. #5
    Unregistered
    Guest
    What do you prefer? I think I'm going to create the visual parts with the text-editor. The reason that I keep bringing this up and asking all these questions is because I consider myself a very experienced Visual Basic programmer. I started C programming because Visual Basic is a higher-level programming lanuage. So, I did a little research and I found out that C\C++ can create the same applications as Visual Basic but with a faster speed, but a slower programming time. So, I want to get down to the core programming with C. The reason that I don't want to work with the visual editor is because I want to stray away from that. That is how it is like in Visual Basic. That click-and-drag method. No, I want to create components with code. Oh, and that code that you supplied me with to create a menu, is that a specific language? What language is it? Thanks.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>What do you prefer?

    Mostly I use VC++6, and so it is easy to create components with the built in resource editor. I am drifting towards using .rc files less though.....


    >>Oh, and that code that you supplied me with to create a menu, is that a specific language? What language is it?

    Nah, its no languge - just a script for the compiler.

    >>The reason that I don't want to work with the visual editor is because I want to stray away from that. That is how it is like in Visual Basic. That click-and-drag method. No, I want to create components with code.

    Dont dismiss the ease of use with resource editors so early on. There's far more important lessons to learn first
    If your coming from VB, you should really look at console programming first as it will teach you how this language properly before you try to focus on windows coding. C/C++ is not like VB - its a very "warts and all" language

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    It is the same, unregistered guy from before except I registered now. Okay, I have been doing console programming for a little while now and I am quite enjoying it. It is not that I'm going to get into Windows programming for another couple of months, just that curiousity has sparked that question of how to make the visual components. I'm going to continue to keep learning console programming and then when I'm confortable with that, I'll move on to Windows. (I'll probably get Charles Petzold's "Programming Windows". Many recommend it.) I'm actually currently working on File I\O. For example:
    Code:
    in_file = fopen("newfile.txt", "r")
    how does the program know the directory of the file to read? After all, to run the program, you have to be in the directory of the executable file. So, how does the program find "newfile.txt"? Thanks.

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Well I suppose the easiest way is to state it explicitly.


    If its in My documents on Win 98 you might use;

    Code:
    in_file = fopen("C:\\My Documents\\newfile.txt", "r")
    Whatever you do dont forget the extra \ as it is an escape charector.

    If you want to find the file you could look up the findfirst() and findnext() fuctions.

    To look them up online try Gookin's Tutorials

  9. #9
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > The reason that I don't want to work with the visual editor is because I want to stray away from that.

    There is no virtue in spurning visual resource editors for raw .RC files - or, indeed, for code. There is no loss in efficiency, no lack of flexibility - it's not a code generator. Resources are space-efficient, easily editable and provide a useful separation between UI design and code.

    I would very much doubt that any large commercial application produced in the last year was produced without the aid of a visual resource editor. Would you draw a picture in a hex editor or a bitmap editor?
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I design comercial UI.
    Unless I want a control on a window, I use the resource editor. I can still modify the controls 'on the fly' but have to spend less time in initial coding.
    As for fopen I believe it searches the folder the exe is running in first, the working directory.
    For folder off the root folder, a subdirectory try

    ".\\Subfolder\\thisfile.txt"


    GetCurrentDirectory(STRING_SIZE, szWorkingDirectory);

    can also be useful

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    So, you don't think there is anything wrong with designing the controls in the editor. I don't know. I'm just going to learn the scripting "language" (if you may) to learn how to program in the controls and then include them in the program. By the way, where do you learn that scripting "language" for the resource files? Thanks.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Imagine you want to design a dialog that displays / edits a contact list. ie names and adresses. Say 20 to 30 controls.
    Do you want to, 'on the fly', adjust all the controls to fit evenly on the dialog? Try printing in WIN32 and you will see what I mean.
    I would rather design the dialog in the editor and then display in the program. Even menus I create in the editor and then turn off and on, hide and show items.
    Best to leave the script.rc and resource.h alone.
    The only time I edit them is if I want the controls to have sequential identifiers for loops. If the editboxes have sequential ID's I can increment a counter to move thru the controls.
    When you can use all the controls including Listviews and Treeviews, then start playing with the files produced by the editor.
    Petzoid describes how to make controls within the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  2. Resource Files....
    By gcn_zelda in forum Windows Programming
    Replies: 2
    Last Post: 12-13-2003, 03:02 PM
  3. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  4. Multiple Resource files
    By doodlak in forum C++ Programming
    Replies: 0
    Last Post: 07-04-2002, 06:13 PM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM