CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 41

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Posts
    19

    Resources ID based on other resources ID

    My problem: I need to give to icons resources identifiers values based on other (buttons) identifiers values.
    example, if i have a button with CM_TEST identifier, i need to have a corresponding icon with a resource ID = CM_TEST+xxxx

    I tried the method explained below without success
    Including Shared (Read-Only) or Calculated Symbols
    http://msdn.microsoft.com/en-us/library/zakskay9.aspx

    So, i follow this method and my rc file contains:

    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "dialogh2.h"
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS


    my dialogh2.h content some icons identifiers as:
    #define IDI_OK (IDOK+20000)
    #define IDI_OK_DISABLED (IDOK+30000)
    #define IDI_CANCEL (IDCANCEL+20000)
    #define IDI_CANCEL_DISABLED (IDCANCEL+30000)

    Result: all identifiers are not calculated and seems to get a value of 0.

    some observations:

    -icon property window show :
    ID: "(IDOK+20000)"
    (quotes are present)

    -when displaying rc resource symbol dialog, my identifiers IDI_OK, IDI_OK_DISABLED ... don't appear (read-only symbols checkbox checked)

    -I did some tests as :
    #define IDI_OK (1+20000)
    same result..
    In all cases, identifiers seems to evaluate to 0 (because they become my app icon and i already have an app icon with ID = 1)


    How to solve this problem ?
    Thank you very much in advance

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Resources ID based on other resources ID

    Quote Originally Posted by pascal_33 View Post

    my dialogh2.h content some icons identifiers as:
    #define IDI_OK (IDOK+20000)
    #define IDI_OK_DISABLED (IDOK+30000)
    #define IDI_CANCEL (IDCANCEL+20000)
    #define IDI_CANCEL_DISABLED (IDCANCEL+30000)
    Are you sure that IDOK and IDCANCEL are already defined, prior to the above #defines? In other words are you certain that windefs.h or winuser.h have already been included somehow? #define is very unintelligent and the compiler probably won't give you a warning if those symbols aren't known yet.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  3. #3
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    yes, they are.

    And i also test different things as:
    #define IDC_TEST 10
    #define IDI_OK (IDC_TEST+100)
    same problem !

    even
    #define IDI_OK (1+100) don't work

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Resources ID based on other resources ID

    You're doing something wrong somewhere else. Build and run this small program as a console app:-

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define IDC_TEST 10
    #define IDI_OK (IDC_TEST+100)
    
    int main (int argc, char *argv[])
    {
    int n = IDI_OK;
    
            printf ("Value of 'n' = %d", n);
            getch ();
    
            return 0;
    }
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  5. #5
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by John E View Post
    You're doing something wrong somewhere else. Build and run this small program as a console app:-

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define IDC_TEST 10
    #define IDI_OK (IDC_TEST+100)
    
    int main (int argc, char *argv[])
    {
    int n = IDI_OK;
    
            printf ("Value of 'n' = %d", n);
            getch ();
    
            return 0;
    }
    You do not understand me. The problem relates to the compilation of rc file.

  6. #6
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Resources ID based on other resources ID

    Quote Originally Posted by pascal_33 View Post
    #define IDI_OK (1+100) don't work
    Doesn't that define a macro which takes one parameter and expands to nothing?
    Try if this works:
    Code:
    #define IDI_OK 1+100
    If that works, then I'm still not sure if you can replace the 1 with IDOK. That is, I'm not sure the IDOK will get expanded. You may need to do something like
    Code:
    #define ADD(x, y) (x + y)
    #define IDI_OK ADD(IDOK, 100)
    Also see http://www.boost.org/doc/libs/1_45_0...doc/index.html
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Resources ID based on other resources ID

    Quote Originally Posted by pascal_33
    -when displaying rc resource symbol dialog, my identifiers IDI_OK, IDI_OK_DISABLED ... don't appear (read-only symbols checkbox checked)
    Afraid your problem is... using resource editor. As a project coded strictly in plain text editor compiles and works perfectly fine.
    Best regards,
    Igor

  8. #8
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by Igor Vartanov View Post
    Afraid your problem is... using resource editor. As a project coded strictly in plain text editor compiles and works perfectly fine.
    not only the resource editor, also the resource compiler (see my reply to D_Drmmr)

  9. #9
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by D_Drmmr View Post
    Doesn't that define a macro which takes one parameter and expands to nothing?
    Try if this works:
    Code:
    #define IDI_OK 1+100
    If that works, then I'm still not sure if you can replace the 1 with IDOK. That is, I'm not sure the IDOK will get expanded. You may need to do something like
    Code:
    #define ADD(x, y) (x + y)
    #define IDI_OK ADD(IDOK, 100)
    Also see http://www.boost.org/doc/libs/1_45_0...doc/index.html
    I have tried a number of different ways and it just does not work. The problem is that in the .rc file the 'calculated' value is replaced by the preprocessor but the rc compiler does not recalculate it but accepts it as a string value.

    #define IDI_X 100
    #define IDI_Y (ID_X + 100)

    ...

    IDI_X ICON ...
    IDI_Y ICON ...

    // in rc file gets replaced thus
    100 ICON ...
    (ID_X + 100) ICON

    which is obviously wrong. It seems that rc will not recalculate expressions that are used as labels in resource scripts.

  10. #10
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Resources ID based on other resources ID

    Quote Originally Posted by pascal_33 View Post
    The problem is that in the .rc file the 'calculated' value is replaced by the preprocessor but the rc compiler does not recalculate it but accepts it as a string value.

    #define IDI_X 100
    #define IDI_Y (ID_X + 100)

    ...

    IDI_X ICON ...
    IDI_Y ICON ...

    // in rc file gets replaced thus
    100 ICON ...
    (ID_X + 100) ICON

    which is obviously wrong. It seems that rc will not recalculate expressions that are used as labels in resource scripts.
    As I said earlier, #define is not in any way intelligent. It performs a simple (textual) search and replace, substituting (textually) one expression for another. Whether your compiler subsequently understands the substituted text will vary from one compiler to another. If the resource compiler doesn't understand the end result there's very little you can do (except to keep modifying your #defines until you arrive at something it does understand).
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  11. #11
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Resources ID based on other resources ID

    Shouldn't that be
    Quote Originally Posted by pascal_33 View Post
    #define IDI_X 100
    #define IDI_Y (IDI_X + 100)
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  12. #12
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Resources ID based on other resources ID

    As already said multiple times, please post a sample project.
    It could have several reasons. For example, we don't know how you are using those resource IDs in your code.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  13. #13
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    @ John E and Marc G
    I fully understand that you request a full project. But it is very complicated because my app rely on OWLNET libraries (https://sourceforge.net/apps/mediawi...itle=Main_Page)
    Nobody want to take hours to install and compile these libraries.

    alanjhd08 did a test, and he got same results as me.

    My main question is how do you understand this MSDN page ?
    http://msdn.microsoft.com/en-us/library/zakskay9.aspx

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Resources ID based on other resources ID

    Quote Originally Posted by pascal_33 View Post
    @ John E and Marc G
    I fully understand that you request a full project.
    No, you didn't understand!
    No one here needs your "full project"!
    We need a very small project that reproduces the same problem you do have now! A very very small! (Or you mean that without linking to "OWLNET libraries" you could not reproduce your problem?
    Victor Nijegorodov

  15. #15
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Resources ID based on other resources ID

    pascal_33 - we all understand how frustrating it is to be constantly asked for a small sample project when you think you've already given us all the relevant information but the simple truth is that we've all been down this road, many times before.

    Just last week I spent over two days trying to solve a newbie's question - only for him to admit that he'd found the problem in a completely different part of the code that he hadn't told anyone about!
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured