CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jun 2003
    Posts
    53

    toolbar prompt resource clash

    I have a problem with strings in my application.

    I have created a string in the String Table which happens to have been allocated a resource number as follows :-

    #define IDS_TDB_LAG 32780

    I have set up the following string :-
    "Dry-Bulb Time Lag"

    I also have a toolbar, with a button which has been automatically assigned the same resource number as follows :-

    #define ID_SUN 32780

    I want to set up a tooltip on this "ID_SUN" button to say "Run SUNCAST"

    I do this by editing the Toolbar Button Properties Prompt.

    HOWEVER...
    This new string replaces the old IDS_TDB_LAG string.

    How can I get around this? What resource numbers can I safely edit?

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: toolbar prompt resource clash

    You can manually edit those IDs from resources.h.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    Thanks Cilu.

    Which resource numbers can I safely edit, and how do I make sure the new resource numbers I choose do not clash with anything else?

    Is it safer to edit the string ID IDS_TDB_LAG or the toolbar button ID ID_SUN?

    Will I need to update the section at the bottom of resource.h labelled :-
    "Next default values for new objects"?

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: toolbar prompt resource clash

    You can safely edit any ID as long as you don't use a number already used by another. Since these are symbolic constants (#defines) their value (with whom they are replaced at precompile time) is not important. The resources are not referenced by the value, but by the symbol:

    Code:
    #define  ID_TAG      1002
                <symbol>  <value>
    You can use any number between 1 and 0xFFFF, as long as they are unique.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    Thanks again Cilu, I'll try that.

    By the way, does anyone have any idea why the system allows the clash to happen in the first place?

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: toolbar prompt resource clash

    It does not allow such a clash. When you say system I don't understand. Do you mean the IDE ?

    Well, for one, the resource compiler will not allow such clashes. For example, if you have 2 string resources with the same ID ( when I mean ID, it is numerical value ) , the resource compiler will flag an error.

    i.e. if you have
    #define IDS_STR1 12345
    #define IDS_STR2 12345

    and
    IDS_STR1 "blah blah1"
    IDS_STR2 "blah blah2"

    You will get an error by the resource compiler.

    Note that the resource compiler will not allow same IDs for same category of resources, but across types is ok. You can have a string table endtry with ID, 12345 and a bitmap with same ID 12345. This is because it is a different resource type.

    Also, you can have the same ID in different DLLs for the same type. You can have 12345 string ID in dll1 and the same 12345 string ID in dll2. Which one gets picked up is dependent on how the string is loaded. When you load a string you call LoadString(module handle, ID ), the module handle specifies which one to use. So if you pass dll1's module handle you get 12345 from dll1 .

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: toolbar prompt resource clash

    Quote Originally Posted by cilu
    You can safely edit any ID as long as you don't use a number already used by another. Since these are symbolic constants (#defines) their value (with whom they are replaced at precompile time) is not important. The resources are not referenced by the value, but by the symbol:

    Code:
    #define  ID_TAG      1002
                <symbol>  <value>
    You can use any number between 1 and 0xFFFF, as long as they are unique.
    Hm.. the symbols are just used by precompiler...so it is the values that are important, right ?

  8. #8
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    Kirants,

    Sorry, I'm not explaining this very well.

    I have a string and a button. Both have the same ID number. This is OK because they are different types of resource :-

    #define IDS_TDB_LAG 32780
    #define ID_SUN 32780

    HOWEVER when I add a TOOLTIP using the toolbar button prompt field, this OVERWRITES the IDS_TDB_LAG string.

    I can only assume that the "system" automatically creates a resource string for the prompt by default with the same number as the button's ID???

    I am renumbering resources at the moment, still getting problems.

  9. #9
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: toolbar prompt resource clash

    Quote Originally Posted by martin_craigen
    Kirants,

    I can only assume that the "system" automatically creates a resource string for the prompt by default with the same number as the button's ID???
    Yes. The IDE is doing that.

    I am renumbering resources at the moment, still getting problems.
    What problems ?
    You just have to renumber the one clashing with some other number. For e.g., if you have a Toolbar button with ID 1234
    #define ID_TOOLBAR_BUTTON1 1234

    and you have a string with same ID #define ID_THIS_IS_NOT_TOOLBAR_TOOLTIP 1234, change the number of this to 1300 or something and now add the tooltip.

  10. #10
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    OK I've got it working now, thanks .... BUT the basic "PROBLEM" still exists

    Can someone PLEASE try to answer the MAIN question , because this will happen again the next time I create a button with a tooltip prompt :-

    WHY DOES THE SYSTEM OVER-WRITE A STRING WITH A TOOLTIP PROMPT???

    Kirants - you say that the IDE creates a resource string with the same ID as the button. WHY does this happen even if there is already an IDS string allocated with this number, i.e. WHY is the system nor clever enough to check for this?

    Do I have to check through ALL my string IDs and Button IDs for clashes, and renumber my string IDs???

    Thanks for all your help so far..............Martin

    (By the way, the reason my initial attempts at renumbering didnt work was because I was having problems trying to get the .rc file to reflect the changes I had made in resource.h. I think part of the problem was Visual SourceSafe ("No, that's not possible, VSS is so easy to use!" I hear you cry).)

  11. #11
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: toolbar prompt resource clash

    Quote Originally Posted by kirants
    Hm.. the symbols are just used by precompiler...so it is the values that are important, right ?
    Of course. I was saying that he symbol is used everywhere, and he can safely edit that ID's value, since he doesn't need do to it manually in tens of places in the code. That is the compilers job, who replaces the symbolic constant with its value.

    Well, of course you can use a resource by the value, say GetDlgItem(1102), but that would be really stupid. And what I said was that a resouce identifier

    #define ID 1102

    can be safelly replaced with

    #define ID 2000

    as long as you reference it everywhere by ID, not 1102 or 2000 in this example.

    BTW, I'm pretty sure that you know what I meant from the first place.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  12. #12
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: toolbar prompt resource clash

    Quote Originally Posted by martin_craigen
    Kirants - you say that the IDE creates a resource string with the same ID as the button. WHY does this happen even if there is already an IDS string allocated with this number, i.e. WHY is the system nor clever enough to check for this?
    It is not clever enough, because it can get tricky. What you may have is a simple case with one .rc and resource.h. But one can have other .rcs included within the main.rc and each of those could have includes other than resource.h. In that case,managing all the IDs isn't gonna be trivial..

    SO, all the IDE does is to just assist you a little bit, and yes, as you see, it does screw up sometimes.

  13. #13
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    Guys,

    I genuinely appreciate your trying to help me, BUT...

    I know I can change ID numbers. And that is what I have done to fix my immediate problem.

    HOWEVER...

    Sorry to repeat myself, but next time I create a button with a tooltip prompt, I MIGHT get the same problem reappearing, e.g. :-

    HYPOTHETICAL SCENARIO

    I have a string #define IDS_DO_NOT_PRESS 32780 "DO NOT PRESS THIS BUTTON"

    If I create a toolbar button #define ID_PLEASE_PRESS (which HAPPENS to be automatically assigned ID number 32780 but is NOTHIN TO DO WITH the above string) and set the tooltip prompt to be "PLEASE PRESS THIS BUTTON", then things get screwed.

    What happens is that IDS_DO_NOT_PRESS string gets OVERWRITTEN, and replace by "PLEASE PRESS THIS BUTTON".

    NOT the desired functionality. WHY does the prompt over-write the un-related string???
    _

  14. #14
    Join Date
    Jun 2003
    Posts
    53

    Re: toolbar prompt resource clash

    kirants,
    I was typing my last post before I saw yours, so my last comments are redundant.

    All it means is that every time I create an automatic tooltip prompt I need to check that it has not over-written a pre-existing string.

    Thanks for your help.

  15. #15
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: toolbar prompt resource clash

    I don't have one handy, but if you open a resource.h file, you'll see down the bottom that it is storing the next value it is going to use for resource IDs. Sometimes this number gets out of whack. Set it to one greater than the highest number currently being used.

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