Re: Resources ID based on other resources ID
Ok... i'm preparing to post a sample project with the problem ;)
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.
Re: Resources ID based on other resources ID
Quote:
Originally Posted by
OReubens
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)
1 Attachment(s)
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
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. :sick:
Re: Resources ID based on other resources ID
Quote:
Originally Posted by
VictorN
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. :sick:
I'm afraid there is no solution to this problem :(
1 Attachment(s)
Re: Resources ID based on other resources ID
Quote:
Originally Posted by
VictorN
So it looks like the compiler is expecting a string or a numeric expression and therefore the expression is not evaluated. :sick:
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)
1 Attachment(s)
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
Re: Resources ID based on other resources ID
Quote:
Originally Posted by
alanjhd08
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).
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.
Re: Resources ID based on other resources ID
Quote:
Originally Posted by
OReubens
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 ;)