CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 41
  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
    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

  6. #6
    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

  7. #7
    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.

  8. #8
    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.

  9. #9
    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)

  10. #10
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Resources ID based on other resources ID

    Don't know if it helps, but a popular problem with the VS resource editor is having two different versions of the .h file, one used when compiling the code, the other by the resource compiler. It's worth checking that you only have one copy of the dialog2.h file on your system.

  11. #11
    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

  12. #12
    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

  13. #13
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by alanjhd08 View Post
    Don't know if it helps, but a popular problem with the VS resource editor is having two different versions of the .h file, one used when compiling the code, the other by the resource compiler. It's worth checking that you only have one copy of the dialog2.h file on your system.
    There is only one dialog2.h file which is normally used as "read-only" file (i follow the microsoft link in my 1st post)

  14. #14
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by D_Drmmr View Post
    Shouldn't that be
    it was only an example for the problem explanation

  15. #15
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by John E View Post
    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).
    Yes, but following microsoft
    http://msdn.microsoft.com/en-us/library/zakskay9.aspx
    it should work !
    but it does not

Page 1 of 3 123 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