文档章节

用Duilib界面库开发的一个日历控件

江河海流
 江河海流
发布于 2013/12/12 11:03
字数 3596
阅读 2331
收藏 7
估考虑使用Duilib这一免费开源的利器,在业务功能实现上,办公自动化少不了日历控件的使用,在网上寻了半天,没有好的开源的日历控件,更多的是web版的日历控件,估决定参考web版的日历控件,使用duilib实现一个winform版的日历,在网上找到的比较炫的一个日历如下:

做web开发的朋友可以在这里找到此控件:

http://www.open-open.com/ajax/ajax20091109225817.htm  

下面我们使用Duilib实现winform版的日历控件:

a、将其web版的资源文件,主要是图片,下载到本地;

b、编写duilib需要使用到的xml文件,Calendar.xml;

     View Code    

 1 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>  2 <Window size="429,470" sizebox="4,4,6,6" caption="0,0,0,30">  3 <VerticalLayout name="VerticalLayoutUI1" pos="205,186,265,216" width="60" height="30" bkimage="body.png" bordercolor="#009DABCE">  4 <Container name="ContainerUI1" pos="0,0,429,50" width="429" height="50">  5 <Button name="BTN_UP_MONTH" text="&lt;&lt;" float="true" pos="18,14,57,36" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />  6 <Button name="BTN_UP_YEAR" text="&lt;&lt;" float="true" pos="276,15,313,40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />  7 <Button name="BTN_DOWN_YEAR" text="&gt;&gt;" float="true" pos="324,15,361,40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />  8 <Combo name="CMB_MONTH" float="true" pos="75,15,175,37" droptype="droplist" width="100" height="22" textpadding="4,1,1,1" normalimage="file='combo.png' source='0,0,100,22' corner='2,2,20,2'" hotimage="file='combo.png' source='0,22,100,44' corner='2,2,22,2'" pushedimage="file='combo.png' source='0,44,100,66' corner='2,2,22,2'">  9 <ListLabelElement text="1月" selected="true" height="23"/> 10 <ListLabelElement text="2月" height="23" /> 11 <ListLabelElement text="3月" height="23" /> 12 <ListLabelElement text="4月" height="23" /> 13 <ListLabelElement text="5月" height="23" /> 14 <ListLabelElement text="6月" height="23" /> 15 <ListLabelElement text="7月" height="23" /> 16 <ListLabelElement text="8月" height="23" /> 17 <ListLabelElement text="9月" height="23" /> 18 <ListLabelElement text="10月" height="23" /> 19 <ListLabelElement text="11月" height="23" /> 20 <ListLabelElement text="12月" height="23" /> 21 </Combo> 22 <Edit name="TXT_YEAR" text="2013" float="true" pos="202,14,262,36" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" /> 23 </Container> 24 <Container name="ContainerUI2" pos="0,44,429,69" width="429" height="25"> 25 <Button name="ButtonUI40" text="星期日" float="true" pos="1,1,62,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 26 <Button name="ButtonUI41" text="星期一" float="true" pos="62,1,123,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 27 <Button name="ButtonUI42" text="星期二" float="true" pos="123,1,184,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 28 <Button name="ButtonUI43" text="星期五" float="true" pos="306,1,367,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 29 <Button name="ButtonUI44" text="星期四" float="true" pos="245,1,306,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 30 <Button name="ButtonUI45" text="星期三" float="true" pos="184,1,245,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 31 <Button name="ButtonUI46" text="星期六" float="true" pos="367,1,428,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 32 </Container> 33 <Container name="ContainerUI3" pos="0,75,429,295" width="429" height="266" bordercolor="#00CEAB9D"> 34 <Button name="ButtonUI5" float="true" pos="1,1,62,46" bkimage="calpad.jpg" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" /> 35 <Button name="ButtonUI6" float="true" pos="62,1,123,46" bkimage="calpad.jpg" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" /> 36 <Button name="ButtonUI7" float="true" pos="123,1,184,46" bkimage="calpad.jpg" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" /> 37 <Button name="ButtonUI8" float="true" pos="184,1,245,46" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 38 <Button name="ButtonUI9" float="true" pos="245,1,306,46" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 39 <Button name="ButtonUI10" float="true" pos="306,1,367,46" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 40 <Button name="ButtonUI11" float="true" pos="367,1,428,46" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 41 <Button name="ButtonUI12" float="true" pos="1,45,62,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 42 <Button name="ButtonUI13" float="true" pos="62,45,123,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 43 <Button name="ButtonUI14" float="true" pos="123,45,184,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 44 <Button name="ButtonUI15" float="true" pos="184,45,245,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 45 <Button name="ButtonUI28" float="true" pos="245,45,306,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 46 <Button name="ButtonUI29" float="true" pos="306,45,367,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 47 <Button name="ButtonUI30" float="true" pos="367,45,428,90" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 48 <Button name="ButtonUI16" float="true" pos="1,89,62,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 49 <Button name="ButtonUI17" float="true" pos="62,89,123,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 50 <Button name="ButtonUI18" float="true" pos="123,89,184,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 51 <Button name="ButtonUI19" float="true" pos="184,89,245,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 52 <Button name="ButtonUI34" float="true" pos="245,89,306,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 53 <Button name="ButtonUI35" float="true" pos="306,89,367,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 54 <Button name="ButtonUI36" float="true" pos="367,89,428,134" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 55 <Button name="ButtonUI20" float="true" pos="1,133,62,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 56 <Button name="ButtonUI21" float="true" pos="62,133,123,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 57 <Button name="ButtonUI22" float="true" pos="123,133,184,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 58 <Button name="ButtonUI23" float="true" pos="184,133,245,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 59 <Button name="ButtonUI31" float="true" pos="245,133,306,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 60 <Button name="ButtonUI32" float="true" pos="306,133,367,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 61 <Button name="ButtonUI33" float="true" pos="367,133,428,178" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 62 <Button name="ButtonUI24" float="true" pos="1,177,62,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 63 <Button name="ButtonUI25" float="true" pos="62,177,123,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 64 <Button name="ButtonUI26" float="true" pos="123,177,184,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 65 <Button name="ButtonUI27" float="true" pos="184,177,245,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 66 <Button name="ButtonUI37" float="true" pos="245,177,306,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 67 <Button name="ButtonUI38" float="true" pos="306,177,367,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 68 <Button name="ButtonUI39" float="true" pos="367,177,428,222" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 69 70 <Button name="ButtonUI24" float="true" pos="1,221,62,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 71 <Button name="ButtonUI25" float="true" pos="62,221,123,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 72 <Button name="ButtonUI26" float="true" pos="123,221,184,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 73 <Button name="ButtonUI27" float="true" pos="184,221,245,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 74 <Button name="ButtonUI37" float="true" pos="245,221,306,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 75 <Button name="ButtonUI38" float="true" pos="306,221,367,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 76 <Button name="ButtonUI39" float="true" pos="367,221,428,266" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 77 </Container> 78 <Container name="ContainerUI4" pos="0,379,429,360" width="429" height="25"> 79 <Button name="ButtonUI47" text="星期日" float="true" pos="1,1,62,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 80 <Button name="ButtonUI48" text="星期一" float="true" pos="62,1,123,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 81 <Button name="ButtonUI49" text="星期二" float="true" pos="123,1,184,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 82 <Button name="ButtonUI50" text="星期三" float="true" pos="184,1,245,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 83 <Button name="ButtonUI51" text="星期四" float="true" pos="245,1,306,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 84 <Button name="ButtonUI52" text="星期五" float="true" pos="306,1,367,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 85 <Button name="ButtonUI53" text="星期六" float="true" pos="367,1,428,26" bkimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;cells.png&apos; source=&apos;0,0,81,81&apos;" hotimage="file=&apos;cells.png&apos; source=&apos;0,81,81,162&apos;" /> 86 </Container> 87 </VerticalLayout> 88 </Window>

c、代码实现如下:  

     View Code    

 1 // App.cpp : Defines the entry point for the application.  2 //  3  4 #include "stdafx.h"  5 //#include "systdate.h"  6 #include <ATLComTime.h>  7  8 class CFrameWindowWnd : public CWindowWnd, public INotifyUI  9 {  10 public:  11  CFrameWindowWnd() { };  12 LPCTSTR GetWindowClassName() const { return _T("UIMainFrame"); };  13 //UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; };  14 UINT GetClassStyle() const { return CS_DBLCLKS; };  15 void OnFinalMessage(HWND /*hWnd*/) { delete this; };  16  17 void Init() {}  18  19 void OnPrepare()  20  {  21 ::GetLocalTime(&m_sysTime);  22  DrawCalendar(m_sysTime);  23  }  24  25 void Notify(TNotifyUI& msg)  26  {  27 if( msg.sType == _T("windowinit") ) OnPrepare();  28 else if( msg.sType == _T("return") )  29  {  30 m_sysTime.wYear  = SetTxtYear(0);  31 m_sysTime.wMonth  = GetCmbMonth();  32  DrawCalendar(m_sysTime);  33  }  34 else if( msg.sType == _T("click") )  35  {  36 CControlUI* pOne = static_cast<CControlUI*>(m_pm.FindControl(msg.ptMouse));  37 if (_tcsicmp(pOne->GetClass(), _T("ButtonUI")) == 0)  38  {  39 //上一月  40 if (_tcsicmp(pOne->GetName(), _T("BTN_UP_MONTH")) == 0)  41  {  42 m_sysTime.wMonth = m_sysTime.wMonth-1 == 0 ? 12 : m_sysTime.wMonth-1;  43  DrawCalendar(m_sysTime);  44  }  45 //上一年  46 else if (_tcsicmp(pOne->GetName(), _T("BTN_UP_YEAR")) == 0)  47  {  48 m_sysTime.wYear  = SetTxtYear(-1);  49 m_sysTime.wMonth  = GetCmbMonth();  50  DrawCalendar(m_sysTime);  51  }  52 //下一年  53 else if (_tcsicmp(pOne->GetName(), _T("BTN_DOWN_YEAR")) == 0)  54  {  55 m_sysTime.wYear  = SetTxtYear(1);  56 m_sysTime.wMonth  = GetCmbMonth();  57  DrawCalendar(m_sysTime);  58  }  59  }  60  }  61 else if( msg.sType == _T("itemselect") ) {  62 if (_tcsicmp(msg.pSender->GetName(), _T("CMB_MONTH")) == 0)  63  {  64 m_sysTime.wMonth  = GetCmbMonth();  65  DrawCalendar(m_sysTime);  66  }  67  }  68  }  69  70  LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)  71  {  72 if( uMsg == WM_CREATE ) {  73  m_pm.Init(m_hWnd);  74  CDialogBuilder builder;  75 CControlUI* pRoot = builder.Create(_T("Calendar1.xml"), (UINT)0, NULL, &m_pm);  76 ASSERT(pRoot && "Failed to parse XML");  77  m_pm.AttachDialog(pRoot);  78 m_pm.AddNotifier(this);  79  Init();  80 return 0;  81  }  82 else if( uMsg == WM_DESTROY ) {  83 ::PostQuitMessage(0L);  84  }  85 else if( uMsg == WM_ERASEBKGND ) {  86 return 1;  87  }  88 LRESULT lRes = 0;  89 if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;  90 return CWindowWnd::HandleMessage(uMsg, wParam, lParam);  91  }  92  93 //绘制日历  94 void DrawCalendar(SYSTEMTIME m_sysTime)  95  {  96 int iDay = 0;  97 char cDay[3] = {0};  98 //int iStartDay = m_sysTime.wDayOfWeek;  99 m_sysTime.wDay = 1; 100 int iStartDay = GetDayOfWeek(m_sysTime); 101 //上月天数 102 int iLastMonthStartDays = 31 - iStartDay; 103 if(m_sysTime.wMonth>1) 104 iLastMonthStartDays = GetMonthDays(m_sysTime.wYear,m_sysTime.wMonth - 1) - iStartDay; 105 //本月天数 106 int iMonthDays = GetMonthDays(m_sysTime.wYear,m_sysTime.wMonth); 107 //下月天数 108 int iNextMonthDays = 0; 109 110 CControlUI* pButtonUI; 111 CContainerUI* pControl = static_cast<CContainerUI*>(m_pm.FindControl(_T("ContainerUI3"))); 112 for(int i = 0;i < 42;i++) 113  { 114 pButtonUI = m_pm.FindSubControlByClass(pControl,_T("ButtonUI"),i); 115 //上月 116 if(i<iStartDay) 117  { 118 iLastMonthStartDays ++; 119 sprintf(cDay,"%d",iLastMonthStartDays); 120 pButtonUI->SetText(cDay); 121 DrawBtnBackImage(pButtonUI,false); 122  } 123 else if(i>iStartDay-1&&iDay<iMonthDays) 124  { 125 iDay++; 126 sprintf(cDay,"%d",iDay); 127 pButtonUI->SetText(cDay); 128 DrawBtnBackImage(pButtonUI,true); 129  } 130 else 131  { 132 iNextMonthDays ++; 133 sprintf(cDay,"%d",iNextMonthDays); 134 pButtonUI->SetText(cDay); 135 DrawBtnBackImage(pButtonUI,false); 136  } 137  } 138  } 139 140 void DrawBtnBackImage(CControlUI* pButtonUI,bool isEnable) 141  { 142 if(isEnable) 143  { 144 pButtonUI->SetEnabled(true); 145 pButtonUI->ApplyAttributeList( 146 _T("normalimage=\"file='cells.png' source='0,0,81,81'\" ")\ 147 _T("hotimage=\"file='cells.png' source='0,81,81,162'\" ")); 148  } 149 else 150  { 151 pButtonUI->SetBkImage(_T("calpad.jpg")); 152 pButtonUI->ApplyAttributeList( 153 _T("normalimage=\"file='calpad.jpg'\" ")\ 154 _T("hotimage=\"file='calpad.jpg'\" ")); 155  } 156  } 157 158 int GetMonthDays(int iY,int iM) 159  { 160 int iTotalDay = 31; 161 if(iM == 2) 162  { 163 //闰年可以被4或者400整除 但是不能被100整除 164 if(iY % 4 ==0 && iY % 100 !=0 || iY % 400 ==0) 165 iTotalDay= 29; 166 else 167 iTotalDay=28; 168  } 169 else if(iM==4 || iM==6 || iM==9||iM==11) 170 iTotalDay = 30; 171 return iTotalDay; 172  } 173 174 int GetDayOfWeek(SYSTEMTIME m_sysTime) 175  { 176  cTime.SetDate(m_sysTime.wYear,m_sysTime.wMonth,m_sysTime.wDay); 177 return cTime.GetDayOfWeek()-1; 178  } 179 180 int GetCmbMonth() 181  { 182 CComboUI* pCmb = static_cast<CComboUI*>(m_pm.FindControl(_T("CMB_MONTH"))); 183 CDuiString cCurMonth = pCmb->GetText(); 184 return atoi(cCurMonth.Left(cCurMonth.GetLength()-1)); 185  } 186 187 int SetTxtYear(int iY) 188  { 189 CEditUI* pTxt = static_cast<CEditUI*>(m_pm.FindControl(_T("TXT_YEAR"))); 190 CDuiString cCurYear = pTxt->GetText(); 191 int iCurYear= 0; 192 iCurYear = atoi(cCurYear) + iY; 193 cCurYear.Format("%d",iCurYear); 194 pTxt->SetText(cCurYear); 195 return iCurYear; 196  } 197 198 199 public: 200  CPaintManagerUI m_pm; 201  SYSTEMTIME m_sysTime; 202  COleDateTime cTime; 203 }; 204 205 206 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) 207 { 208  CPaintManagerUI::SetInstance(hInstance); 209  CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath()); 210 211 HRESULT Hr = ::CoInitialize(NULL); 212 if( FAILED(Hr) ) return 0; 213 214 CFrameWindowWnd* pFrame = new CFrameWindowWnd(); 215 if( pFrame == NULL ) return 0; 216 // pFrame->Create(NULL, _T("日历控件测试"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); 217 pFrame->Create(NULL, _T("日历控件测试"), UI_WNDSTYLE_DIALOG, WS_EX_STATICEDGE | WS_EX_APPWINDOW, 0, 0, 600, 320); //禁止双击放大 218 pFrame->CenterWindow(); 219 pFrame->ShowWindow(true); 220  CPaintManagerUI::MessageLoop(); 221 222  ::CoUninitialize(); 223 return 0; 224 }

d、运行看一下效果吧!

 

© 著作权归作者所有

下一篇: DOS经典游戏
江河海流
粉丝 10
博文 44
码字总数 73431
作品 0
黄浦
私信 提问
Duilib 入门教程: 怎么创建一个自定义的窗口

一直想找一个好用UI 界面库,看过Direct UI,也想过 金山的界面库,后来找到了这个Duilib 现在的软件界面很多都是利用XML 来布局和定位。 像迅雷7,QQ,金山卫士等 Duilib 也是利用XML来记录控...

junwong
2012/03/23
1K
0
如何使duilib与视频播放联系起来?

@婷儿 你好,想跟你请教个问题:你好,我上次问过你一个duilib和视频播放的问题。现在想进一步的了解,希望能得到你的回答,谢谢!duilib的控件库比较有限,我不知道你是如何把视频放入那个布...

蔡天宇
2012/06/24
4.2K
4
搞定AutoCAD中嵌入使用duilib

一直对AutoCAD默认只支持MFC的丑陋界面很是不满,而duilib是我极其喜欢的一个小巧的界面库,因此就考虑是否可以在cad中使用duilib。之前试过直接启动duilib做的界面是没有问题的,这两天研究...

平原君
2012/09/02
0
2
duilib源码探析之事件绑定

引言 之前自己写界面库的时候,未找到好方法响应消息,使用的是最笨的方式,在主窗口的响应函数中,判断是哪个子窗口,进而再判断是哪个按钮。 最近使用云信duilib,正好研究了下duilib按钮与...

shuilan0066
2018/04/13
0
0
DuiLib在VS2012下的编译

DuiLib在VS2012下的编译 DuiLib在VS2012下的编译 一. 直接修改*.vcxproj 1.修改vcxproj文件 2.使用VS2012打开工程 3.修改对应Plamtform Toolset 3.编译报错 error C2065 ;代码加一回车,编译...

MtrS
05/08
0
0

没有更多内容

加载失败,请刷新页面

加载更多

java思维导图整理

jmm https://www.edrawsoft.cn/viewer/public/s/b0178374373697; redis https://www.edrawsoft.cn/viewer/public/s/5691c269955848 map https://www.edrawsoft.cn/viewer/public/s/b67533638......

流光韶逝
1分钟前
0
0
Gnu/Linux 防止暴力扫描及其它

RedHat7 手工脚本: # iptables iptables -A INPUT -i eno16777728 -p tcp -m multiport --destination-port 135,136,137,138,139,445,4899,1900 -j LOG iptables -A INPUT -p tcp -m multip......

晒太阳的小猪
23分钟前
9
0
OSChina 周一乱弹 —— 满周岁就去挣钱!

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @ tom_tdhzz:一直期待了很久,这是第二次来圆明园,也是特意来这里,只是才发现只有历史现实不在了。#今日歌曲推荐# 分享王晰的单曲《南屏晚...

小小编辑
41分钟前
419
9
解决Structure needs cleaning

简介 今天在同步文件的时候有一个目录突然报错 Structure needs cleaning 百度了一下发现使用xfs_repair可以解决 操作 因为我做的是raid5 ,可能是昨天我重启了机器的缘故,所以我要做的是先...

bboysoulcn
今天
6
0
Dubbo服务暴露与注册

前面的文章中,我们讲解了Dubbo是如何进行配置的属性的初始化的,并且讲到,Dubbo最终会将所有的属性参数都封装为一个URL对象,从而以这个URL对象为基准传递参数。本文则主要讲解Dubbo是如何...

爱宝贝丶
今天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部