introduction

  • 更多控件用法,请参考 here 和 源码。
  • 本文的代码基于这里
  • 本文将介绍menu控件

xml文件添加代码

基于上一篇, 继续向basic.xml中添加下面的代码。 xml完整源码在文末。

这段代码添加到最小化按钮的上面

    <HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
<Control />
<!--设置按钮-->
<Button class="btn_wnd_settings" name="settings" margin="4,6,0,0"/> <Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0" />
<Box width="21" margin="4,6,0,0">
<Button class="btn_wnd_max" name="maxbtn"/>
<Button class="btn_wnd_restore" name="restorebtn" visible="false"/>
</Box>
<Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0"/>
</HBox>

核心代码是

<!--设置按钮-->
<Button class="btn_wnd_settings" name="settings" margin="4,6,0,0"/>

项目文件配置

menu控件来自另一个项目ui_components, 而ui_component又依赖项目libcef_dll_wrapperlibcef_dll_wrapper位于文件夹third_party下。

stage 1

从源码目录拷贝ui_componentlibcef_dll_wrapperlibs文件夹到先前创建好的kit的文件夹下,此时目录结构如下:

.kit
├─base
├─build
├─duilib
├─libs
├─third_party
└─ui_components

stage 2

习惯将项目输出到VS默认输出的目录Debug, 所以将项目ui_componentslibcef_dll_wrapper输出目录中间目录改为如下:

name value
输出目录 $(SolutionDir)$(Configuration)|
中间目录 $(Configuration)|

stage 3

设置ui_components项目链接lib目录指向 kit\libs\。 打开ui_components属性->库管理器->常规->附加库目录->编辑,改为下面的值:

$(SolutionDir)kit\libs\

Note: 注意Release和Debug需要都修改。效果图

stage 4

为什么要做上面的配置? 因为 项目ui_components需要依赖libs目录下的nim_libcef库

代码中关联

BasicForm.h

  • 打开BasicForm.h,类中添加下面的代码用于关联界面控件。
	// settings按钮
ui::Button* psettings_;

监听选择子项事件

类中继续添加下面的代码,用于监听滑块的值发生变化

	// settings按钮点击事件
bool OnSettingsBtnClicked(ui::EventArgs* msg);

BasicForm.cpp

InitWindow函数

  • 转到BasicForm.cpp,找到 InitWindow 函数,向其增加下面的代码
void BasicForm::InitWindow()
{
......
// 12.关联设置按钮
//----------------------------------------------------------------------------------------
psettings_ = dynamic_cast<ui::Button*>(FindControl(L"settings"));
// 关联点击事件
if (psettings_)
{
psettings_->AttachClick(nbase::Bind(&BasicForm::OnSettingsBtnClicked, this, std::placeholders::_1));
}
}

OnSettingsBtnClicked

OnSettingsBtnClicked函数源码如下:

bool BasicForm::OnSettingsBtnClicked(ui::EventArgs* msg)
{
// 点击设置按钮,弹出菜单
RECT rect = msg->pSender->GetPos();
ui::CPoint point;
point.x = rect.left - 175;
point.y = rect.top + 10;
ClientToScreen(m_hWnd, &point); nim_comp::CMenuWnd* pmenu = new(std::nothrow) nim_comp::CMenuWnd(NULL);
if (pmenu)
{
ui::STRINGorID xml(L"settings_menu.xml");
pmenu->Init(xml, _T("xml"), point);
} return false;
}

运行结果

xml完整源码

<?xml version="1.0" encoding="UTF-8"?>
<Window size="900,600" caption="0,0,0,35">
<VBox bkcolor="bk_wnd_darkcolor">
<HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
<Control />
<!--设置按钮-->
<Button class="btn_wnd_settings" name="settings" margin="4,6,0,0"/> <Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0" />
<Box width="21" margin="4,6,0,0">
<Button class="btn_wnd_max" name="maxbtn"/>
<Button class="btn_wnd_restore" name="restorebtn" visible="false"/>
</Box>
<Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0"/>
</HBox> <!--下面是中间的控件-->
<VBox padding="30, 30, 30, 30" >
<HBox height="120">
<VBox>
<!-- Buttons -->
<Button class="btn_global_blue_80x30" name="btn_blue" text="blue" />
<Button class="btn_global_white_80x30" name="btn_white" text="white"/>
<Button class="btn_global_red_80x30" name="btn_red" text="red"/>
</VBox> <!--checkbox-->
<VBox>
<CheckBox class="checkbox_font12" name="checkbox1" text="checkbox1" margin="0,5,0,10" selected="true"/>
<CheckBox class="checkbox_font12" name="checkbox2" text="checkbox2" margin="0,5,0,10"/>
<CheckBox class="checkbox_font12" name="checkbox3" text="checkbox3" margin="0,5,0,10"/>
</VBox> <!-- option-->
<VBox>
<Option class="circle_option_2" name="option1" group="option_group" text="option1" margin="0,3,0,10" selected="true"/>
<Option class="circle_option_2" name="option2" group="option_group" text="option2" margin="0,3,0,10"/>
<Option class="circle_option_2" name="option3" group="option_group" text="option3" margin="0,3,0,10"/>
</VBox> <HBox>
<!-- List -->
<VListBox class="list" name="list" padding="5,3,5,3">
</VListBox>
<VBox> <!-- Buttons -->
<CheckBox class="checkbox_font12" name="list_checkbox_add_to_top" text="add to top" margin="0,5,0,10"/>
<Button class="btn_global_blue_80x30" name="list_btn_add" text="add" /> <CheckBox class="checkbox_font12" name="list_checkbox_remove_all" text="del all?" margin="0,5,0,10"/>
<Button class="btn_global_white_80x30" name="list_btn_remove" text="remove"/>
</VBox>
</HBox> <!-- TreeView -->
<TreeView class="list" name="tree" padding="5,3,5,3" margin="20">
</TreeView>
</HBox> <!--第二行控件开始-->
<HBox height="85">
<VBox>
<!--combobox-->
<Combo class="list" name="combo" height="30" margin="0,12,0,0" padding="6" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
<HBox>
<RichEdit class="simple input" name="rich_edit_1" text="输入演示" height="30" margin="0,3" padding="6,6,6" promptmode="true" prompttext="Single line text control" promptcolor="lightcolor"/>
<CheckBox class="checkbox_font12" name="rich_edit_readonly" text="read only" margin="0,5,0,10"/>
</HBox>
</VBox> <HBox>
<VBox>
<!-- Progress -->
<HBox margin="0,10" height="32">
<Progress class="progress_blue" name="progress" value="0" margin="10"/>
</HBox> <!-- Slider -->
<HBox margin="0,0,0,10" height="32">
<Slider class="slider_green" name="slider" value="0" margin="10"/>
</HBox>
</VBox> <VBox width="120">
<CircleProgress name="circle_progress" circular="true" height="80" width="80"
circlewidth="10" bgcolor="gray" fgcolor="green" value="0" clockwise="true" min="1" max="100" margin="10"
textpadding="10,32,10,10" normaltextcolor="darkcolor" indicator="logo_18x18.png"/>
</VBox> </HBox>
</HBox> </VBox> <!--下面是中间的控件 结束-->
</VBox>
</Window>

nim_duilib(11)之menu(1)的更多相关文章

  1. nim_duilib(12)之menu(2)

    introduction 更多控件用法,请参考 here 和 源码. 本文将介绍menu的选项注册回调 before starting 本文的代码基于上一篇 stage1 回到项目demo_xml, ...

  2. 自动化安装smokeping-2.6.11脚本

    自动化安装Smokeping-2.6.11脚本 一.目的 1.1 监控目的 为方便监测各数据中心网络状况,自定义全国各节点,从而发现网络异常,判断网络故障. 1.2 本文目的 快速部署Smokepin ...

  3. Python Tkinter Menu

    本人想开发一个简易的搜图GUI,基于此,选择用Tkinter模块开发. 需要开发出菜单栏 1 from Tkinter import * 2 3 4 root = Tk() 5 root.title( ...

  4. Jquery学习笔记--性能优化建议

    一.选择器性能优化建议 1. 总是从#id选择器来继承 这是jQuery选择器的一条黄金法则.jQuery选择一个元素最快的方法就是用ID来选择了. 1 $('#content').hide(); 或 ...

  5. 云盘WEB资料下载链接

    入门三板斧:http://www.cnblogs.com/jikey/p/3613082.html 入门看这个:http://pan.baidu.com/s/1pJqJvAV 入门JS视频:http: ...

  6. 【转载】Linux系统启动流程

    原文:Linux系统启动流程 POST(Power On Self Test/上电自检)-->BootLoader(MBR)-->Kernel(硬件探测.加载驱动.挂载根文件系统./sbi ...

  7. 课程设计(部分代码)之java版(记事本)

    /* *java课程设计之记事本(coder @Gxjun) * 编写一个记事本程序 * 要求: * 用图形用户界面实现. * 能实现编辑.保存.另存为.查找替换等功能. * 提示:使用文件输入输出流 ...

  8. CentOS6.4安装Smokeping节点监控软件

    Smokeping:它是rrdtool的作者制作的,在图形显示方面很漂亮,可以用来很好的检测网络状态和稳定性,下面简单说一下Smokeping的安装以及配置方法. 0.首先关闭selinux和防火墙 ...

  9. Android知识思维导图

    注:图片来源于网络,谢谢分享. 一.  项目目录结构: 布局控件 ListVIew控件 Widget:(窗口小部件) Activity Manager 二.  应用程序的5个模块构成: Activit ...

随机推荐

  1. 自定义 Word 模板

    自定义 Word 模板 目录 必要设置 样式设置 标题样式 多级列表 封面 正文 引用目录 页码 页眉 图标 自定义模板保存 样式导入和导出 批量删除多余空白段落 必要设置 显示所有格式标记 选择&q ...

  2. 如何反向推断基因型文件中的参考碱基(REF/ALT)?

    目录 需求 解决 方法一 方法二 需求 客户随手丢来一个基因型文件,类似于hapmap格式,只是少了中间多余的那几列,像这种类hapmap格式文件,往往是芯片数据. 这样的数据因为缺乏等位基因:参考碱 ...

  3. 【Perl示例】整合多个文件

    这个需求是在生信分析中几乎天天用到,各种语言都能实现,也都各有特点.这次以perl为例. 已知 文件CT-VS-CON.All.xls为全部蛋白表达矩阵及其差异分析结果. 文件Homo_sapiens ...

  4. mysql—从字符串中提取数字(类型1)

    select reason,CHAR_LENGTH(reason),mid(reason,5,CHAR_LENGTH(reason)-5)+0 from `table` 解释: CHAR_LENGTH ...

  5. socket编程:多路复用I/O服务端客户端之select

    其实在之前的TCP之中,我们编程实现了多进程,多线程机制下的TCP服务器,但是对于这种的TCP服务器而言,存在太大的资源局限性.所以我们可以是用I/0模型中的多路复用I/O模型来进行编程. 他的具体思 ...

  6. JavaBean内省与BeanInfo

    Java的BeanInfo在工作中并不怎么用到,我也是在学习spring源码的时候,发现SpringBoot启动时候会设置一个属叫"spring.beaninfo.ignore", ...

  7. TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况

    TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况 请访问原文链接:https://sysin.org/blog/tlsv1-3-support/,查看最新版. ...

  8. 如果通过 IP 判断是否是爬虫

    通过 IP 判断爬虫 如果你查看服务器日志,看到密密麻麻的 IP 地址,你一眼可以看出来那些 IP 是爬虫,那些 IP 是正常的爬虫,就像这样: 在这密密麻麻的日志里面,我们不仅要分辨出真正的爬虫 I ...

  9. Docker学习(一)——安装docker

    Suse12上安装docker   对于suse13.2之后的版本,因为docker已经被添加到了suse仓库中,直接使用sudo zypper install docker即可.   suse12不 ...

  10. Apache架构师的30条设计原则

    本文作者叫 Srinath,是一位科学家,软件架构师,也是一名在分布式系统上工作的程序员. 他是 Apache Axis2 项目的联合创始人,也是 Apache Software 基金会的成员. 他是 ...