How unique do resource IDs have to be?

This is a discussion on How unique do resource IDs have to be? within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing an app that I may want to insert into a bigger project later as a separate dialog. I'm ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    How unique do resource IDs have to be?

    I'm writing an app that I may want to insert into a bigger project later as a separate dialog. I'm curious if the IDs for things in the resource have to be completely unique to the project, or only to the specific resource/dialog? Like can a control in 1 dialog have the same ID number as a control in another dialog? The reason I'm questioning this at all is that all the functions like GetDlgItem() require a handle to the specific dialog which contains the control. That leads me to believe I can order my controls anyway I please so long as they're in a separate dialog.
    Last edited by Viper187; 08-30-2008 at 05:30 PM.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Yea you can set the same ID to two different controls. It also does not matter if they are in the same dialog, or separate dialog. If they are in the same dialog, and you call SetDlgItemText() or something similar it will set the text of both controls. I'm not sure about GetDlgItemText() since i've never tried it. But yes, since the controls are in separate dialog windows you can specify which window you want and get the control you want from just that window/control without worry about the other.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    Thanks. I wanted to verify that before I got too far along. heheh

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by scwizzo View Post
    Yea you can set the same ID to two different controls. It also does not matter if they are in the same dialog, or separate dialog.
    IMO resource IDs should be unique on a single window (dialog). The resource editor also will not allow it in most IDEs.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If you do not ever need to call them, they can be set to whatever you damn well please (-1 is good enough for me). If you need to get the window handle by its identifier, however, its a good practice to make them unique.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I'm with Novacain in that I've never seen non-unique resource IDs. MFC wizards will not allow any items with the same resource ID and I believe it would also confuse the resource compiler.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I am of the impression that the OP is dynamically creating resources.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If the resources are dynamically created, then I'd just use an incrementing number, e.g:
    Code:
    int getNextRscNo()
    {
        static int rscNo = STARTING_RSC_NO;   // Some number that is clearly higher than the existing resources from your resource file. 
    
        rscNo++;
        if (rscNo == MAXINT)
            rscNo = STARTING_RSC_NO;
        return rscNo;
    }
    It will take an AWFULL long time to reach a number that is too big, but the above code is "fixing" that by returning to the original number - which should work as long as that number is not still in use.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting out a resource manager
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 11-10-2008, 07:12 PM
  2. unmanaged resource
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2008, 04:23 AM
  3. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 01:07 AM
  4. Generic Resource_Manager WIP with lots TODO
    By Shamino in forum C++ Programming
    Replies: 19
    Last Post: 02-01-2006, 01:55 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21