Thread: Resources

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    35

    Resources

    hey all,
    No matter which site I go to, every tutorial explains resources very vaguely saying it is compiler specific. I don't really understand them at all . I know you have to have a source file(is it the 1 that is executed and is it .c or .cpp?), and header and a resource script file. The problem is no matter which examples i put in there they never work. They work with the same code but never when I try to change a name or something simple like that. Not to sure on how to set one up, so can some1 sugggest a detailed site(tryed forger's but it was vague to me atleast ) or explain it a lil' on here? Most to the example source codes are in .c. Thx l8er

    -fire

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    MSD: About resources (microsoft specific but there's not really that much difference between resource compiler syntax these days.



    Resource definition statements These define your resources within your resource script, there may be some very minor differences in syntax between resource compilers.

    The only resource compiler specific tweak that springs to mind is for MinGW/Dev-Cpp: you need to #include windows.h in your resource script (*.rc file) to ensure that the compiler will recognise those resource definition statements. You may also have to #define IDC_STATIC -1, ie. for MinGW/Dev-Cpp resource scripts always start with:
    Code:
    #include <windows.h>
    #if !defined IDC_STATIC
    #define IDC_STATIC -1
    #endif
    #include "name_of_your_resource_defines_header.h"
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    thx for the info, that site has tons of good stuff on it. Will try to figure this out now .
    Say I was going to add a resource. First I would add a *.rc file to my source file (*.cpp). Then I would make a header file(*.h) with the defines needed by the *.rc file. Then I would #include "resource.h" into my source file and add the code to the menu section inplace of null.
    Is this right? Will read more into resources tonight. thx again
    -Can some1 give an example of a resource that works with Dev C++, I tried the example off of Forgers again and it shows an erroe with the #include "resource.h" command. Has this happened 2 anyone else and what am I doing wrong?

    -fire
    Last edited by firestorm; 04-10-2005 at 01:44 PM.

  4. #4
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Okay, first, you wouldn't add the *.rc to your *.cpp. In Dev C++. simply right clikc on your project in the dropdown list and selsct add to Project. Then add your *.rc. Then yes, you would make your resource.h and add it to your project and your *.rc.

    As to your second question, I'll walk you through the making of a basic resource.

    Always start out with windows.h and your definition of IDC_STATIC.
    Code:
    #include <windows.h>
    
    #ifndef IDC_STATIC
    #define IDC_STATIC -1
    #endif
    You could go into winuser.h and find the part of the code that defines IDC_STATIC and remove it from the if statement that keeps it from being defined. But unless you really
    know what you're doing, you shouldn't mess with standard headers.

    Now, here's a basic menu resource.
    Code:
    #include <windows.h>
    
    #ifndef IDC_STATIC
    #define IDC_STATIC -1
    #endif
    
    IDM_MENU MENU DISCARDABLE
    BEGIN
      POPUP "&Test"
      BEGIN
        MENUITEM "&Click This",    IDM_TEST_CLICKTHIS
      END
    END
    Now that we've got the resource written, we need a header with definitions.
    Code:
    #ifndef RESOURCE_H  /*Not really necessary, but is good practice with headers.*/
    #define RESOURCE_H /*Same as above.*/
    
    #define IDM_MENU           0x1000
    #define IDM_TEST_CLICKTHIS 0x1011
    
    #endif
    And, simply include them innyour source and your resource.
    Code:
    #include <windows.h>
    
    #ifndef IDC_STATIC
    #define IDC_STATIC -1
    #endif
    
    #include "resource.h"
    
    IDM_MENU MENU DISCARDABLE
    BEGIN
      POPUP "&Test"
      BEGIN
        MENUITEM "&Click This",    IDM_TEST_CLICKTHIS
      END
    END
    If you still get errors with that code, (assuming I didn't mess up ), then you've got real problems. If you still get errors on the #include "resource.h" line the you may have mispalced the file and it's not in your main directory.

    If you still get a syntax error, then it could be a number of things. Have you ever actually opened up the windows.h file or any other headers? If so you might have accidentally made some minute change that's messing up your whole code.

    For that menu, you shound't even need windows.h in your resource so you could try removing it. If that gets rid of your rescource errors, then there's a problem with the header itself. You could try reinstalling Dev C++ entirely.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    35
    will try it. If it don't work and I can't fix it I will just reload Dev. Sorta frustrating to do all this but learning a whole new language always is ...thx again

    -fire

  6. #6
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Well, if it doesn't work, just keep in mind that you aren't necessarily bad at programming. You're just incredibly unlucky.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 05:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-14-2004, 11:28 PM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-14-2002, 11:36 PM