首页 > REDM基础教程 > REDM基础教程11-控件的XML属性规则
2016十一月11

REDM基础教程11-控件的XML属性规则

[隐藏]

  上一节的Test下载–>

Test.zip

   

上一节我们加入了ComboboxEx和ListBoxEx两个新控件,并注册了它们,这一节我们来讲下这两个控件的属性构成,怎么快速查找它们的属性

  

1.属性类介绍

     

首先XML结点名称我们都清楚了,是由DMDECLARE_CLASS_NAME宏的第二个参数决定的,那么这个XML结点支持哪些Attribute(属性)呢

DM使用统一的规范方式,所有的Attribute(属性)都位于DMAttr这个名字空间中,一般放在最上面,

属性类的命名为:XXXXAttr(XXXX为控件类名),如:

/// <summary>
	///		<see cref="DM::ListBoxEx"/>的xml属性定义
	/// </summary>
	class ListBoxExAttr:public DUIScrollBaseAttr
	{
	public:
		static wchar_t* INT_itemheight;                                           ///< 项的默认高度,示例:itemheight="10"
		static wchar_t* INT_cursel;                                               ///< 当前选项,示例:cursel="1"
		
         ....
         	DMAttrValueInit(ListBoxExAttr,INT_itemheight)DMAttrValueInit(ListBoxExAttr,INT_cursel)

  

1.1.属性注释介绍

  

之所以注释是///<,是因为doxygen能自动识别这种注释,并把它加入到chm文档中,所以如果增加新属性,建议使用此种方式

112.png

 

1.2.属性命名规则

  

命名规则统一为:类型_属性名

如:INT_itemheight表示这是一个INT类型,它在xml中的Attribute属性名为itemheight

设计器也使用这种方式来构造对应类型的prop属性,它的属性配置全部位于DesignerRes\DMAttr.xml中:

	<DUIListBoxExAttr
	INT_itemheight="{20}项的默认高度,此值不支持动态变化,示例:itemheight=10"
	INT_cursel="{-1}当前选项,示例:cursel=1"

左边表示了类型和属性名称,右边{}中表示初始值,后面跟注释(tips),下图显示了这样配置后设计的显示效果,注意观察初值,注释

103.gif

  

1.3.属性赋值规则

  

前面可以看到,所有的Attr类,每个成员变量都是static wchar*,都代表一个属性,static成员变量是需要初始化的

使用宏DMAttrValueInit来为属性赋初值,宏定义位于DMXmlCrack.h中

#define  DMAttrValueInit(cls,x)						__declspec(selectany)   wchar_t*  cls::x = DMInitAttrDispatch::GetAttrValue(L#cls,L#x);

初值就是Attribute属性名,即INT_itemheight = "itemheight";INT_cursel="cursel";COLOR_clritembg="clritembg"

在DEBUG或设计器模式下,还会生成

DMAttr::DMInitAttrDispatch::m_pDoc

这个全局XML变量,如果设计器里的DesignerRes\DMAttr.xml没有被外部初始化,可以使用它来初始化一份,当然可能你需要手动调整下

    

经过前面的分析,我们可以发现,要查看一个控件的所有属性,只需查看.h中最上方的Attr类的成员变量,它们都是static,每个成员变量代表一个属性

DM_BEGIN_ATTRIBUTES()
    DM_INT_ATTRIBUTE(DMAttr::ListBoxExAttr::INT_itemheight, m_iDefItemHei, DM_ECODE_OK)
    ....
DM_END_ATTRIBUTES()   

  

有人可能有疑问,为什么不直接用L"itemheight",而非得使用DMAttr::ListBoxExAttr::INT_itemheight呢

1.doxygen可以解析到Attr名字域,从而在代码中就能生成所有属性的帮助文件

2.属性集中在一起管理,方便使用者快速知道这个控件有哪些属性名称,这些属性又是什么类型的

3.设计器也使用这种方式来配置prop的类型,名称,初值

  

 

   

 下一节教程:REDM基础教程12-手工增加皮肤

   

文章作者:hgy413
本文地址:http://hgy413.com/3730.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

15 Responses to “REDM基础教程11-控件的XML属性规则”

  1. #1 minecraft 回复 | 引用 Post:2018-10-04 08:52

    bookmarked!!, I like your site!

  2. #2 minecraft 回复 | 引用 Post:2018-10-04 14:26

    If you are going for best contents like I do, simply visit this
    web site daily for the reason that it provides feature contents, thanks

  3. #3 minecraft 回复 | 引用 Post:2018-10-04 22:38

    Please let me know if you’re looking for a article writer for your weblog.
    You have some really great articles and I think I would be
    a good asset. If you ever want to take some of the load off, I’d absolutely
    love to write some content for your blog in exchange for a link back to mine.
    Please send me an email if interested. Thanks!

  4. #4 minecraft 回复 | 引用 Post:2018-10-05 16:04

    Wow that was strange. I just wrote an really long comment but after
    I clicked submit my comment didn’t appear.
    Grrrr… well I’m not writing all that over again. Anyways, just wanted to say great blog!

  5. I have been surfing on-line greater than 3 hours lately, but
    I by no means discovered any attention-grabbing article like yours.
    It is beautiful value enough for me. In my opinion, if all site owners and bloggers made excellent content as you did, the web shall be a lot
    more helpful than ever before.

  6. If you wish for to get a great deal from this paragraph then you have to apply
    these methods to your won blog.

  7. #7 Coconut Oil 回复 | 引用 Post:2018-10-23 05:14

    Incredible! This blog looks exactly like my old one! It’s on a entirely different
    subject but it has pretty much the same page layout and design. Great choice of colors!

  8. #8 Coconut Oil 回复 | 引用 Post:2018-10-24 06:36

    Hello my family member! I wish to say that this article
    is amazing, nice written and include almost all important infos.
    I’d like to see more posts like this .

  9. We stumbled over here different web address and thought I may as well check things out.
    I like what I see so now i am following you. Look forward to looking over your web
    page for a second time.

  10. #10 Coconut Oil Benefits 回复 | 引用 Post:2018-10-29 23:31

    It’s appropriate time to make a few plans for the future and
    it is time to be happy. I have learn this post and if I
    may I desire to suggest you few fascinating issues or suggestions.

    Perhaps you can write next articles relating to this article.
    I wish to learn more things about it!

  11. #11 quest bars cheap 回复 | 引用 Post:2018-11-04 00:41

    I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get bought an shakiness over that you wish be delivering the following.
    unwell unquestionably come further formerly again since exactly the
    same nearly very often inside case you shield this hike.

  12. Greetings! I know this is kinda off topic however I’d figured I’d ask.

    Would you be interested in exchanging links or maybe guest
    writing a blog post or vice-versa? My blog covers a lot of the same subjects as
    yours and I feel we could greatly benefit from each other.
    If you happen to be interested feel free to shoot me
    an email. I look forward to hearing from you! Terrific blog by the way!

  13. #13 Sling TV 回复 | 引用 Post:2018-11-11 01:09

    I constantly emailed this blog post page to all my friends,
    as if like to read it then my contacts will too.

  14. Sling tv coupons and promo codes for november 2018
    Admiring the commitment you put into your site and in depth information you provide.
    It’s good to come across a blog every once in a while that
    isn’t the same outdated rehashed information.
    Excellent read! I’ve saved your site and I’m adding your RSS feeds to my
    Google account. Sling tv coupons and promo codes for november 2018

  15. Oh my goodness! Impressive article dude! Thank
    you, However I am experiencing difficulties with your RSS.
    I don’t know why I am unable to subscribe to it.
    Is there anyone else getting similar RSS problems? Anyone who knows the
    answer can you kindly respond? Thanx!!

发表评论