0

I'm not sure if my Title for this question entirely describes accurately enough what I am trying to do but hopefully I'll explain myself better in this description.

I want to be able to configure a CEdit control by reading in its dwStyle parameters as a string from an XML file i.e. :-

CreateEx(   WS_EX_CLIENTEDGE,L"EDIT",L"",WS_CHILD|WS_VISIBLE,
                m_xPosition,m_yPosition,m_width,m_height,
                m_pParent->m_hWnd,( HMENU )m_resourceID );

In this case, the dwStyle is WS_CHILD|WS_VISIBLE.

What I'd like to be able to do is to have this style as a string:

string dwStyleString = "WS_CHILD|WS_VISIBLE";

and to then use this string as the dwStyle parameter but obviously in a way whereby it is recognized that it should be interpreted by the function not as a string, but as the function parameter.

Chances are that this is not possible, but hoping someone out there may be able to help, or possibly suggest another way of doing this.

Thanks in advance for any responses,

Dave

mrk
  • 4,999
  • 3
  • 27
  • 42
davidpcl1977
  • 111
  • 2
  • 9
  • possible duplicate of http://stackoverflow.com/questions/726664/string-to-enum, http://stackoverflow.com/questions/201593/is-there-a-simple-script-to-convert-c-enum-to-string, and possibly many others. – sbi Jun 22 '11 at 10:54
  • Thanks for that sbi - had a thorough search to make sure I wasn't creating a duplicate, but probably due to the difficulty I had in phrasing the question none of these showed up. – davidpcl1977 Jun 22 '11 at 11:59
  • Don't sweat over it. I remembered that I've seen those. (My search string was "[c++] enum string", BTW.) – sbi Jun 22 '11 at 12:33
  • 1
    I don't think either of those are dups. `"MY_ENUM"` -> `MY_ENUM` is a completely different kettle of fish to `"MY_ENUM_1|MY_ENUM2"` -> `MYENUM_1|MY_ENUM_2`. – Lightness Races in Orbit Jun 23 '11 at 19:27

1 Answers1

1

There is no built-in way, you have to do it yourself. Fist tokenize the string using | as delimiter, trim whitespace from substrings, determine the int value of each substring (follow up sbi's links for that, but plain old if-else-if will do as well), and finally combine all values with bitwise OR operator.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • Got it working - as suggested had to go the DIY route and create a map ( map ) and then read the value from the XML file, as suggested tokenize this and do a search in a while loop. – davidpcl1977 Jun 24 '11 at 07:52