使用字符串来描述函数参数
我不确定这个问题的标题是否完全准确地描述了我想要做的事情,但希望我能在这个描述中更好地解释自己。
我希望能够通过从 XML 文件中读取其 dwStyle 参数作为字符串来配置 CEdit 控件,即:-
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 );
在本例中,dwStyle
是 WS_CHILD|WS_VISIBLE
。
我想要做的就是将此样式作为字符串:
string dwStyleString = "WS_CHILD|WS_VISIBLE";
然后使用此字符串作为 dwStyle 参数,但显然以一种可以识别它应该被解释的方式函数不是作为字符串,而是作为函数参数。
这很可能是不可能的,但希望有人能够提供帮助,或者可能建议另一种方法来做到这一点。
预先感谢您的任何回复,
戴夫
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置的方法,你必须自己做。首先使用 | 标记字符串作为分隔符,修剪子字符串中的空格,确定每个子字符串的 int 值(请跟踪 sbi 的链接,但普通的旧 if-else-if 也可以),最后使用按位 OR 运算符组合所有值。
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.