duilib教程之duilib入门简明教程12.简单控件介绍
前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用。 由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界面比较土鳖,但是想要换成百度杀毒那样的界面,只需要更换图片即可,如果有哪位小伙伴能够提供一些控件样式,那就再好不过啦~
首先利用一下前面教程的框架,效果图如下:![]()
main.cpp的代码如下:
- class CDuiFrameWnd : public WindowImplBase
- {
- public:
- virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
- virtual CDuiString GetSkinFile() { return _T("duilib.xml"); }
- virtual CDuiString GetSkinFolder() { return _T(""); }
- };
- int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
- {
- CPaintManagerUI::SetInstance(hInstance);
- CDuiFrameWnd duiFrame;
- duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
- duiFrame.CenterWindow();
- duiFrame.ShowModal();
- return 0;
- }
复制代码
XML代码如下(由于前面的教程里都一一介绍了各种属性,所以以后的XML就不一一注释了):
- <?xml version="1.0" encoding="UTF-8"?>
- <Window size="800,600" mininfo="600,400" caption="0,0,0,32" sizebox="4,4,4,4">
- <VerticalLayout bkcolor="#FFF0F0F0" bkcolor2="#FFAAAAA0">
- <!-- 标题栏区 -->
- <HorizontalLayout height="32" bkcolor="#FFE6E6DC" bkcolor2="#FFAAAAA0">
- <VerticalLayout />
- <VerticalLayout width="77">
- <Button name="minbtn" tooltip="最小化" float="true" pos="0,5,22,24" width="23" normalimage=" file='SysBtn\MinNormal.bmp' " hotimage=" file='SysBtn\MinFocus.bmp' " pushedimage=" file='SysBtn\MinFocus.bmp' "/>
- <Button name="maxbtn" tooltip="最大化" float="true" pos="22,5,44,24" width="23" normalimage=" file='SysBtn\MaxNormal.bmp' " hotimage=" file='SysBtn\MaxFocus.bmp' " pushedimage=" file='SysBtn\MaxFocus.bmp' " />
- <Button name="restorebtn" visible="false" tooltip="还原" float="true" pos="22,5,44,24" width="23" normalimage=" file='SysBtn\StoreNormal.bmp' " hotimage=" file='SysBtn\StoreFocus.bmp' " pushedimage=" file='SysBtn\StoreFocus.bmp' " />
- <Button name="closebtn" tooltip="关闭" float="true" pos="44,5,74,24" width="28" normalimage=" file='SysBtn\CloseNormal.bmp' " hotimage=" file='SysBtn\CloseFocus.bmp' " pushedimage=" file='SysBtn\CloseFocus.bmp' "/>
- </VerticalLayout>
- </HorizontalLayout>
- </VerticalLayout>
- </Window>
复制代码
前面教程的Hello World就是一个大大的按钮,大家对按钮应该很熟悉了,下面我们来几个按钮样式吧:
XP默认按钮
win7默认按钮
百度杀毒
百度卫士
![]()
上述图片资源请点击这里下载,下载后解压到exe目录即可,此时Debug文件夹如下(别忘了前面教程的SysBtn文件夹哦):
我们先用DuiDesigner添加一些按钮,并且把他们排整齐,如图:![]()
保存之后就可以看到这几个按钮的pos等属性了,再手动将这几个Button节点加到前面的XML中,并添加图片属性,如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <Window size="800,600" mininfo="600,400" caption="0,0,0,32" sizebox="4,4,4,4">
- <VerticalLayout bkcolor="#FFF0F0F0" bkcolor2="#FFAAAAA0">
- <!-- 标题栏区 -->
- <HorizontalLayout height="32" bkcolor="#FFE6E6DC" bkcolor2="#FFAAAAA0">
- <VerticalLayout />
- <VerticalLayout width="77">
- <Button name="minbtn" tooltip="最小化" float="true" pos="0,5,22,24" width="23" normalimage=" file='SysBtn\MinNormal.bmp' " hotimage=" file='SysBtn\MinFocus.bmp' " pushedimage=" file='SysBtn\MinFocus.bmp' "/>
- <Button name="maxbtn" tooltip="最大化" float="true" pos="22,5,44,24" width="23" normalimage=" file='SysBtn\MaxNormal.bmp' " hotimage=" file='SysBtn\MaxFocus.bmp' " pushedimage=" file='SysBtn\MaxFocus.bmp' " />
- <Button name="restorebtn" visible="false" tooltip="还原" float="true" pos="22,5,44,24" width="23" normalimage=" file='SysBtn\StoreNormal.bmp' " hotimage=" file='SysBtn\StoreFocus.bmp' " pushedimage=" file='SysBtn\StoreFocus.bmp' " />
- <Button name="closebtn" tooltip="关闭" float="true" pos="44,5,74,24" width="28" normalimage=" file='SysBtn\CloseNormal.bmp' " hotimage=" file='SysBtn\CloseFocus.bmp' " pushedimage=" file='SysBtn\CloseFocus.bmp' "/>
- </VerticalLayout>
- </HorizontalLayout>
- <!-- 客户区 -->
- <HorizontalLayout>
- <Button text="XP" float="true" pos="20,14,0,0" width="60" height="25" normalimage=" file='BtnStyle\XP\button_nor.png' " hotimage=" file='BtnStyle\XP\button_over.png' " pushedimage=" file='BtnStyle\XP\button_down.png' " focusedimage=" file='BtnStyle\XP\button_focus.png' " />
- <Button text="win7" float="true" pos="20,50,0,0" width="60" height="25" normalimage=" file='BtnStyle\win7\button_nor.png' " hotimage=" file='BtnStyle\win7\button_over.png' " pushedimage=" file='BtnStyle\win7\button_down.png' " focusedimage=" file='BtnStyle\win7\button_focus.png' " />
- <Button text="百度杀毒" float="true" pos="20,86,0,0" width="102" height="35" normalimage=" file='BtnStyle\BDKV\button_nor.png' " hotimage=" file='BtnStyle\BDKV\button_over.png' " pushedimage=" file='BtnStyle\BDKV\button_down.png' " />
- <Button float="true" pos="20,132,0,0" width="171" height="46" normalimage=" file='BtnStyle\BDKV2\button_nor.png' " hotimage=" file='BtnStyle\BDKV2\button_over.png' " pushedimage=" file='BtnStyle\BDKV2\button_down.png' " />
- </HorizontalLayout>
- </VerticalLayout>
- </Window>
复制代码
效果如下:![]()
用鼠标移上去,或者点击一下,看看是不是和系统按钮一样呢^_^
下面我们介绍一下duilib的另一种特性,那就是可以定制默认样式,这样做有什么好处呢?
假如我们有10个按钮,按钮样式都一样,如果用之前介绍的方式,则需要在每个Button节点都指定图片背景、宽度、高度等信息,一旦需要改动任何一个属性,则需要在10个按钮里面都改一次,所以为了方便修改,我们可以指定一个默认样式,就算有100个按钮,我们也只需要改一次属性。方法如下:
给节点添加一个Default节点即可,其中name属性填写控件的名字,value属性添加控件的属性的值,不过需要将双引号【"】换成【"】,单引号【'】换成【'】,单引号也可以不转换。
XML如下(由于标题栏基本不再变化,所以后面的教程将省略那一段XML):
- <Window size="800,600" mininfo="600,400" caption="0,0,0,32" sizebox="4,4,4,4">
- <Default name="Button" value=" height="25" width="60" normalimage="file='BtnStyle\XP\button_nor.png'" hotimage="file='BtnStyle\XP\button_over.png'" pushedimage="file='BtnStyle\XP\button_down.png'" focusedimage="file='BtnStyle\XP\button_focus.png'" " />
- <VerticalLayout bkcolor="#FFF0F0F0" bkcolor2="#FFAAAAA0">
- <!-- 客户区 -->
- <HorizontalLayout>
- <Button text="XP" float="true" pos="20,14,0,0" height="25" />
- <Button text="win7" float="true" pos="20,50,0,0" height="25" />
- <Button text="百度杀毒" float="true" pos="20,86,0,0" height="25" />
- <Button float="true" pos="20,132,0,0" height="25" />
- </HorizontalLayout>
- </VerticalLayout>
- </Window>
复制代码
XML是不是清爽多了呢^_^ 注意,这里面要指定height属性,不然会看不到按钮,估计是因为放在了HorizontalLayout水平布局里。(如果是VerticalLayout ,应该是指定width属性,这个只是猜测,暂未验证~(^o^)/~)
不过你会发现,启动的时候,最小化按钮图片不对了,那是因为最小化按钮没有指定focusedimage属性,所以就用了默认的focusedimage属性,只需要指定一下就行了。![]()
按钮的用法就介绍完啦,大家可以看到UI设计器里面还有下面这些控件,
其中:
Control是所有控件的基类,一般放图片啥的就用它了。
Label和Text是用于放文字的,其中Label的对齐功能比Text要好一些,所以我一般用Label,这个对应于MFC的Static控件。
Edit显然就是编辑框啦,Button就不用多说了吧~
上面提到的控件都是简单控件,拖到设计器上就能直观的看到效果,绝大部分属性都和Button一样,就不赘述了,所有控件的所有属性都在【duilib控件 XML属性列表
属性列表.zip (6.49 KB, 下载次数: 138) 】里有详细说明(不过有一点点遗漏,需要去看源码),下一节将介绍复杂控件。
duilib教程之duilib入门简明教程12.简单控件介绍的更多相关文章
- duilib教程之duilib入门简明教程13.复杂控件介绍
首先将本节要介绍的控件全部拖到界面上,并调整好位置,如图: 然后将Name属性改成其他名字, 不能是[控件名+UI+数字]这种,因为这是DuiDesigner默认的名字,它不会实际写 ...
- 2013 duilib入门简明教程 -- 自绘控件 (15)
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...
- duilib教程之duilib入门简明教程17.事件处理和消息响应
界面的显示方面就都讲完啦,下面来介绍下控件的响应. 前面的教程只讲了按钮和Tab的响应,即在Notify函数里处理.其实duilib还提供了另外一种响应的方法,即消息映射DUI_BEGIN_ME ...
- duilib教程之duilib入门简明教程14.部分bug 2
上一个教程中提到了ActiveX的Bug,即如果主窗口直接用变量生成,则关闭窗口时会产生崩溃 如果用new的方式生成,则不会崩溃,所以给出一个临时的快速解决方案,即主窗口都用new生成,_t ...
- duilib教程之duilib入门简明教程15.自绘控件
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如菜单控件 ...
- duilib教程之duilib入门简明教程11.部分bug
一.WindowImplBase的bug 在第8个教程[2013 duilib入门简明教程 -- 完整的自绘标题栏(8)]中,可以发现窗口最大化之后有两个问题, 1.最大化按钮的样式还是没 ...
- duilib教程之duilib入门简明教程3.第一个程序 Hello World
小伙伴们有点迫不及待了么,来看一看Hello World吧:新建一个空的win32项目,新建一个main.cpp文件,将以下代码复制进去: #include <windows.h> #in ...
- 2013 duilib入门简明教程 -- 简单控件介绍 (12)
前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用. 由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界 ...
- duilib教程之duilib入门简明教程9.界面布局
上一个教程实现的标题栏代码中,并没有看到处理自适应窗口大小的代码,但是窗口大小变化后,按钮的位置会跟着变化,这是因为我们将按钮放到了HorizontalLayout.VerticalLayout,这样 ...
随机推荐
- 《代码大全2》读书笔记 Week2
<代码大全2>第四.五章 第四章“关键的‘构建’决策”主要有以下三要点:1.每种编程语言都有优点和缺点,程序员应根据需要选择编程语言,尽量选择熟悉的语言以提高生产效率.作为一种表达工具,编 ...
- 枚举对象中的属性 for . . in
枚举对象中的属性:把对象中所有的属性和值都取出来 使用 for . . . in 语句 语法: for(var 变量 in 对象){ } for . . . in 语句 对象中有几个属性,循 ...
- Nginx集群配置启动报错
- 【转载】带你吃透RTMP
RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写,它是由Adobe公司提出的一种应用层的协议,用来解决多媒体数据传输流的多路复用(Multiplexing) ...
- PHP FTP 常量
常量 描述 PHP FTP_ASCII 3 FTP_TEXT 3 FTP_BINARY 3 FTP_IMAGE 3 FTP_TIMEOUT_SEC 3 FTP_AUTOSEEK ...
- SXOI2018酱油记
Day 0: 嗯前一天刚听说要去参加省选(可能以前也说了不过没听见),作为弱省高一的蒟蒻准备去打打酱油.下午去五中试机啥也没敲晃荡一圈又回去了.今年来也就是打打酱油心情自然是很平静,真不知道明年现在我 ...
- NX二次开发-创建圆弧(圆心-半径)UF_CURVE_create_arc
NX9+VS2012 #include <uf.h> #include <uf_curve.h> #include <uf_ui.h> #include <u ...
- xcode5 添加Build Phases脚本
http://www.runscriptbuildphase.com/ 版权声明:本文为博主原创文章,未经博主允许不得转载.
- hdu多校第六场1012 (hdu6645) Stay Real 假博弈,真贪心
题意: 给你一个小根堆,从根开始拿,拿走子节点被拿完后才可以拿走父节点,两个人依次拿,谁拿的节点总和大谁获胜,问你谁有必胜策略. 题解: 小根堆中,每个点的权值总是不小于父亲节点的权值.所以无论怎么取 ...
- python+tushare获取A股所有股票代码和名称列表
接口:stock_basic 描述:获取基础信息数据,包括股票代码.名称.上市日期.退市日期等 注:tushare模块下载和安装教程,请查阅我之前的文章 输入参数 名称 | 类型 ...