Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert Resource Names to IDs

Convert Resource Names to IDs

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++xmlhelplearning
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cagespear
    wrote on last edited by
    #1

    I have a requirement in MFC where I have a number of controls whose names are stored in the xml file. I wish to fetch these id names from xml file, convert it to CWnd objects and then take some customization action like apply some backgrnd color and all. My problem is - how do I retrieve resource Ids when I have resource names ? Regs Cage

    R I C 4 Replies Last reply
    0
    • C cagespear

      I have a requirement in MFC where I have a number of controls whose names are stored in the xml file. I wish to fetch these id names from xml file, convert it to CWnd objects and then take some customization action like apply some backgrnd color and all. My problem is - how do I retrieve resource Ids when I have resource names ? Regs Cage

      R Offline
      R Offline
      Rane
      wrote on last edited by
      #2

      Have you seen this[^]. Regards, Rane

      C C 2 Replies Last reply
      0
      • C cagespear

        I have a requirement in MFC where I have a number of controls whose names are stored in the xml file. I wish to fetch these id names from xml file, convert it to CWnd objects and then take some customization action like apply some backgrnd color and all. My problem is - how do I retrieve resource Ids when I have resource names ? Regs Cage

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        The answer is up to you. We have no way of giving any solid recomendations without lots more information. As Rane implied, you are asking us for a lot of work, which you won't get... Does the xml file describe control positions and names? You could read in the xml file, and give the first control you find ID=100, second one ID=101, and so on. Store this name->ID mapping in a (gasp) map container. When you want to look up a control by name later, look up the ID in that map. And that's just one idea. Iain.

        C 1 Reply Last reply
        0
        • R Rane

          Have you seen this[^]. Regards, Rane

          C Offline
          C Offline
          cagespear
          wrote on last edited by
          #4

          Wow! that was really helpful. I don't think my issue was that "elongated". Anyways, I had an idea to do it myself but was looking out for a way which can save me from saving un-necessary info in xml apart from ctrl ID names. Thanks Cage

          1 Reply Last reply
          0
          • C cagespear

            I have a requirement in MFC where I have a number of controls whose names are stored in the xml file. I wish to fetch these id names from xml file, convert it to CWnd objects and then take some customization action like apply some backgrnd color and all. My problem is - how do I retrieve resource Ids when I have resource names ? Regs Cage

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            cagespear wrote:

            I have a requirement in MFC where I have a number of controls whose names are stored in the xml file.

            What's the 'name of the control' ? Controls doesn't have a name, they have an Id and maybe a title. The Id is unique. I guess you are talking about the Id that you supply in the resource editor (like IDC_MYCONTROL) ? Is that what you are talking about ? If yes, then there is no way (AFAIK) to convert such a 'string' into the real Id. The thing is that these Id's are in fact simple #define that will be replaced by the preprocessor by a numerical value. Can't you use the numerical value directly ? Open your resource file with a text editor and you can directly look at the numerical values of the Ids. That is the easiest solution I think (if I understood you correctly).

            Cédric Moonen Software developer
            Charting control [v1.5] OpenGL game tutorial in C++

            C 1 Reply Last reply
            0
            • R Rane

              Have you seen this[^]. Regards, Rane

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              Is your link correct ? Because I'm coming to a post which is a question ("how to filter the packets enter in to our network in VC++?") and has nothing to do with the original question :confused:.

              Cédric Moonen Software developer
              Charting control [v1.5] OpenGL game tutorial in C++

              R 1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                The answer is up to you. We have no way of giving any solid recomendations without lots more information. As Rane implied, you are asking us for a lot of work, which you won't get... Does the xml file describe control positions and names? You could read in the xml file, and give the first control you find ID=100, second one ID=101, and so on. Store this name->ID mapping in a (gasp) map container. When you want to look up a control by name later, look up the ID in that map. And that's just one idea. Iain.

                C Offline
                C Offline
                cagespear
                wrote on last edited by
                #7

                Sorry if my query was vague. Perhaps, I deserved a "can you give more details" type reply rather than a rude "goto this URL and " As for your idea which is more constructive than Rane's, let me give some more detail. Ctrl IDs are autogenerated by compiler and may get over-written so I don't want to store them in the XML. What I was thinking is to store ID Names IDC_X1 in the xml and then retrieve the ctrl ID corresponding to the string "IDC_X1". May be it has a very simple solution which didnt click in my mind but is it "asking too much" or "getting my homework done" type question ? Thanks Cage

                C 2 Replies Last reply
                0
                • C Cedric Moonen

                  cagespear wrote:

                  I have a requirement in MFC where I have a number of controls whose names are stored in the xml file.

                  What's the 'name of the control' ? Controls doesn't have a name, they have an Id and maybe a title. The Id is unique. I guess you are talking about the Id that you supply in the resource editor (like IDC_MYCONTROL) ? Is that what you are talking about ? If yes, then there is no way (AFAIK) to convert such a 'string' into the real Id. The thing is that these Id's are in fact simple #define that will be replaced by the preprocessor by a numerical value. Can't you use the numerical value directly ? Open your resource file with a text editor and you can directly look at the numerical values of the Ids. That is the easiest solution I think (if I understood you correctly).

                  Cédric Moonen Software developer
                  Charting control [v1.5] OpenGL game tutorial in C++

                  C Offline
                  C Offline
                  cagespear
                  wrote on last edited by
                  #8

                  You are right Cedric, I intended to convert "IDC_MYCONTROL" into its numeric ID equivalent. The reason - I didnt want to use numeric IDs directly was because they are generated by the compiler and may be duplicated/get changed while working on the resource file. Thanks a ton for taking an extra effort to understand a rather vague question posted by me(I should have given exact details, my bad). I had lost all hopes after Rane gave me an answer which certainly made me feel low about the question I asked. Thanks again! Cage

                  1 Reply Last reply
                  0
                  • C cagespear

                    Sorry if my query was vague. Perhaps, I deserved a "can you give more details" type reply rather than a rude "goto this URL and " As for your idea which is more constructive than Rane's, let me give some more detail. Ctrl IDs are autogenerated by compiler and may get over-written so I don't want to store them in the XML. What I was thinking is to store ID Names IDC_X1 in the xml and then retrieve the ctrl ID corresponding to the string "IDC_X1". May be it has a very simple solution which didnt click in my mind but is it "asking too much" or "getting my homework done" type question ? Thanks Cage

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #9

                    cagespear wrote:

                    Ctrl IDs are autogenerated by compiler

                    It is generated by the resource editor, not by the compiler. It means that once your UI is done and you don't touch it anymore, you can recompile your project as many times as you like and the Ids won't be changed. Furthermore, nothing prevents you to open the resource file with a text editor and assign the Ids yourself manually (you have to take care about not assigning an existing value). So, I think using the control Id in your xml is perfectly fine (and that's the way I would follow). If you design your UI, adding new controls won't change the Id of existing controls (AFAIK because I never saw something like that happening).

                    Cédric Moonen Software developer
                    Charting control [v1.5] OpenGL game tutorial in C++

                    C 1 Reply Last reply
                    0
                    • C cagespear

                      Sorry if my query was vague. Perhaps, I deserved a "can you give more details" type reply rather than a rude "goto this URL and " As for your idea which is more constructive than Rane's, let me give some more detail. Ctrl IDs are autogenerated by compiler and may get over-written so I don't want to store them in the XML. What I was thinking is to store ID Names IDC_X1 in the xml and then retrieve the ctrl ID corresponding to the string "IDC_X1". May be it has a very simple solution which didnt click in my mind but is it "asking too much" or "getting my homework done" type question ? Thanks Cage

                      C Offline
                      C Offline
                      Cedric Moonen
                      wrote on last edited by
                      #10

                      I'm sorry, I made a mistake: the Ids are defined in the resource.h file, not in the rc file. So, you don't even need to open it with a text editor, you can open the resource.h file directly and check the Ids or assign them yourself.

                      Cédric Moonen Software developer
                      Charting control [v1.5] OpenGL game tutorial in C++

                      1 Reply Last reply
                      0
                      • C Cedric Moonen

                        cagespear wrote:

                        Ctrl IDs are autogenerated by compiler

                        It is generated by the resource editor, not by the compiler. It means that once your UI is done and you don't touch it anymore, you can recompile your project as many times as you like and the Ids won't be changed. Furthermore, nothing prevents you to open the resource file with a text editor and assign the Ids yourself manually (you have to take care about not assigning an existing value). So, I think using the control Id in your xml is perfectly fine (and that's the way I would follow). If you design your UI, adding new controls won't change the Id of existing controls (AFAIK because I never saw something like that happening).

                        Cédric Moonen Software developer
                        Charting control [v1.5] OpenGL game tutorial in C++

                        C Offline
                        C Offline
                        cagespear
                        wrote on last edited by
                        #11

                        Cedric Moonen wrote:

                        you can recompile your project as many times as you like and the Ids won't be changed

                        I was not referring to re-compilation changing the Ids, here's my case - My resource file has more than 30k records and there are lots of merge operations happening on RC because so many people are working on the same project everyday. A lot of times there is a clash on IDs on which a developer has to change the Ids to make them unique. That is why we were reluctant to use numeric IDs. May be there is no easy way to go about it, but we will/are trying to somehow use ID name itself and not numeric ID. Regards Cage

                        1 Reply Last reply
                        0
                        • C Cedric Moonen

                          Is your link correct ? Because I'm coming to a post which is a question ("how to filter the packets enter in to our network in VC++?") and has nothing to do with the original question :confused:.

                          Cédric Moonen Software developer
                          Charting control [v1.5] OpenGL game tutorial in C++

                          R Offline
                          R Offline
                          Rane
                          wrote on last edited by
                          #12

                          The link I posted earlier was an incorrect link and the correct link is here[^] Regards, Rane

                          1 Reply Last reply
                          0
                          • C cagespear

                            I have a requirement in MFC where I have a number of controls whose names are stored in the xml file. I wish to fetch these id names from xml file, convert it to CWnd objects and then take some customization action like apply some backgrnd color and all. My problem is - how do I retrieve resource Ids when I have resource names ? Regs Cage

                            I Offline
                            I Offline
                            Iain Clarke Warrior Programmer
                            wrote on last edited by
                            #13

                            As your problem becomes clearer, you might want to have a look at the following article by Anna-Jayne Metcalfe: Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET[^] Updated versions are at her companies website: http://www.riverblade.co.uk/products/resorg/downloads.html[^] I can't believe you'd really need 30,000 IDs though. You can reuse control IDs if they're on different windows / dialog boxes. The only trouble I have with many dialogs spread across many DLLs is to make sure dialog IDs are unique. Now, if you have 30000 dialogs, start running and screaming now. Iain.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups