-
January 5th, 2011, 05:34 AM
#1
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
-
January 5th, 2011, 09:11 AM
#2
Re: Resources ID based on other resources ID
Originally Posted by pascal_33
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
-
January 5th, 2011, 11:35 AM
#3
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
-
January 5th, 2011, 11:54 AM
#4
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
-
January 5th, 2011, 02:24 PM
#5
Re: Resources ID based on other resources ID
Originally Posted by pascal_33
#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
-
January 5th, 2011, 06:28 PM
#6
Re: Resources ID based on other resources ID
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
-
January 6th, 2011, 04:27 AM
#7
Re: Resources ID based on other resources ID
Originally Posted by John E
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.
-
January 6th, 2011, 04:29 AM
#8
Re: Resources ID based on other resources ID
Originally Posted by D_Drmmr
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.
-
January 6th, 2011, 04:31 AM
#9
Re: Resources ID based on other resources ID
Originally Posted by Igor Vartanov
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)
-
January 6th, 2011, 04:42 AM
#10
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.
-
January 6th, 2011, 05:00 AM
#11
Re: Resources ID based on other resources ID
Originally Posted by pascal_33
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
-
January 6th, 2011, 05:16 AM
#12
Re: Resources ID based on other resources ID
Shouldn't that be
Originally Posted by pascal_33
#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
-
January 6th, 2011, 05:35 AM
#13
Re: Resources ID based on other resources ID
Originally Posted by alanjhd08
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)
-
January 6th, 2011, 05:37 AM
#14
Re: Resources ID based on other resources ID
Originally Posted by D_Drmmr
Shouldn't that be
it was only an example for the problem explanation
-
January 6th, 2011, 05:39 AM
#15
Re: Resources ID based on other resources ID
Originally Posted by John E
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|