CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 41 of 41
  1. #31
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Ok... i'm preparing to post a sample project with the problem

  2. #32
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Resources ID based on other resources ID

    The operation is pretty clear tbh.

    #define ID_ONE 1
    #define ID_TWO (ID_ONE+1)

    Then use ID_TWO as a resource ID in a resource file.

    If the ID can be interpreted as either string or numeric, it'll parsed and processed but not evaluated and used as a string resource.
    If the ID can be interpreted as numeric only, it'll be parsed, processed and evaluated numerically.


    What this means:
    Any "loadable" resource (icon, bitmap, dialog, html, manifest, ....) will be added as a string resource.
    So for ID_TWO you will get a loadable resource named "1+1" rather than having numeric ID 2.

    Any item which is an (numerically) identifiable part of a resource (resource string, an ID of a control on a dialog) will be evaluated to having the value 2.

  3. #33
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by OReubens View Post
    The operation is pretty clear tbh.

    #define ID_ONE 1
    #define ID_TWO (ID_ONE+1)

    Then use ID_TWO as a resource ID in a resource file.

    If the ID can be interpreted as either string or numeric, it'll parsed and processed but not evaluated and used as a string resource.
    If the ID can be interpreted as numeric only, it'll be parsed, processed and evaluated numerically.


    What this means:
    Any "loadable" resource (icon, bitmap, dialog, html, manifest, ....) will be added as a string resource.
    So for ID_TWO you will get a loadable resource named "1+1" rather than having numeric ID 2.

    Any item which is an (numerically) identifiable part of a resource (resource string, an ID of a control on a dialog) will be evaluated to having the value 2.
    I agree, I think you're right.
    But what can I do to get my icon ID dependent of buttons ID values (that was my first aim)

  4. #34
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Here is a sample project
    in the dialog box, you will see only 2 icons

    But if you look at the test1.rc source code, you should expect 3 icons
    Note that the rc editor give an error (on IDI_MYICON1), because it is unable to interpret it
    Attached Files Attached Files

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

    1. You resource file compiles (I used VS2010) with the warning
    Code:
    warning RC2182: duplicate dialog control ID 2
    2. If I comment out the line
    Code:
    //    ICON            IDI_MYICON1,IDR_MAINFRAME3,238,55,20,20
    in your .rc file then the resource view becomes available and what you could see is the ID of the icon "..\test1\res\cancel2.ico" is "(1999+2)"
    So it looks like the compiler is expecting a string or a numeric expression and therefore the expression is not evaluated.
    Victor Nijegorodov

  6. #36
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by VictorN View Post
    1. You resource file compiles (I used VS2010) with the warning
    Code:
    warning RC2182: duplicate dialog control ID 2
    2. If I comment out the line
    Code:
    //    ICON            IDI_MYICON1,IDR_MAINFRAME3,238,55,20,20
    in your .rc file then the resource view becomes available and what you could see is the ID of the icon "..\test1\res\cancel2.ico" is "(1999+2)"
    So it looks like the compiler is expecting a string or a numeric expression and therefore the expression is not evaluated.
    I'm afraid there is no solution to this problem

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

    Re: Resources ID based on other resources ID

    Quote Originally Posted by VictorN View Post
    So it looks like the compiler is expecting a string or a numeric expression and therefore the expression is not evaluated.
    As I said, this works perfectly fine for both compilers, cl and rc:
    Code:
    #define IDD          100
    #define IDC_BUTTON1  1000
    #define IDC_BUTTON2  (IDOK + 20000)
    #define IDC_BUTTON3  (IDOK + 30000)
    Attached Files Attached Files
    Best regards,
    Igor

  8. #38
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Resources ID based on other resources ID

    Hi,

    I've added an ICON to this, and in this case the expression is not evaluated, even when using rc from the command line (I have VS2008 installed)

    From the MSDN note, it looks like this might work with older versions of the resource compiler, e.g. from VS .NET (2003)

    Alan
    Attached Files Attached Files

  9. #39
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by alanjhd08 View Post
    Hi,

    I've added an ICON to this, and in this case the expression is not evaluated, even when using rc from the command line (I have VS2008 installed)

    From the MSDN note, it looks like this might work with older versions of the resource compiler, e.g. from VS .NET (2003)

    Alan
    I agree with you. That don't work for loadables resources.
    However, Igor Vartanov test is interesting showing it is possible to order (IDC1= IDC0+1, IDC2=IDC0+2 ...) a serie of controls which may be useful in some cases (loop treatments relying on controls ID).

  10. #40
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Resources ID based on other resources ID

    there is a solution, even a dynamic one, but you'll need extra tools since the regular resource compiler won't work.

    * Have a .h witht he button id's
    * have a .h with the icon id's. You create/update it as part of your build, it needs to have regular '#define ID value' lines not '#define ID expression'.
    * include both H's in the resource symbols
    * make the .rc compilation dependant on the .h (may not be needed in 2010, explicit dependant is needed in VS2008).

    While unusual, .h and .cpp files in your project can be the result of a tool generating those files. prior to the compiler picking them up for compilation. You sort of make your own "precompiler" in a way.

  11. #41
    Join Date
    Jan 2011
    Posts
    19

    Re: Resources ID based on other resources ID

    Quote Originally Posted by OReubens View Post
    there is a solution, even a dynamic one, but you'll need extra tools since the regular resource compiler won't work.

    * Have a .h witht he button id's
    * have a .h with the icon id's. You create/update it as part of your build, it needs to have regular '#define ID value' lines not '#define ID expression'.
    * include both H's in the resource symbols
    * make the .rc compilation dependant on the .h (may not be needed in 2010, explicit dependant is needed in VS2008).

    While unusual, .h and .cpp files in your project can be the result of a tool generating those files. prior to the compiler picking them up for compilation. You sort of make your own "precompiler" in a way.
    Thanks. This seem a bit complicated but I'll think about it

Page 3 of 3 FirstFirst 123

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