当前位置: 首页 > news >正文

duiLib 利用布局文件显示一个窗口并响应事件

窗口布局文件:

<?xml version="1.0" encoding="UTF-8"?>
<!--界面布局-->
<!-- 窗口设置 -->
<Window roundcorner="5,5" size="600,450"  mininfo="80,60" ><!--定义默认字体--><Font id="0" name="微软雅黑" size="12" bold="false" default="true" shared="true" /><Font id="1" name="微软雅黑" size="12" bold="true" shared="true" /><VerticalLayout bkcolor="#FFFFFFFF" bordersize="2" bordercolor="#FF0934DA"><!--标题栏区域--><HorizontalLayout name="header" height="36" bkcolor="#FF4775CC"><HorizontalLayout><Control width="10"/><Label name="apptitle" text="我是标题" font="1" textcolor="#FFFFFFFF" /></HorizontalLayout>  <HorizontalLayout height="25" width="96"><Button name="minbtn" tooltip="最小化" height="18" width="26" normalimage="file='minimize.png'" hotimage="file='minimize_h.png'" pushedimage="file='minimize_p.png'"/><Button name="maxbtn" tooltip="最大化" height="18" width="25" normalimage="file='maximize.png'" hotimage="file='maximize_h.png'" pushedimage="file='maximize_p.png'"/><Button name="restorebtn" visible="false" tooltip="恢复" height="18" width="25" normalimage="file='restore.png'" hotimage="file='restore_h.png'" pushedimage="file='restore_p.png'"/> <Button name="closebtn" tooltip="关闭" height="18" width="43" normalimage="file='close.png'" hotimage="file='close_h.png'" pushedimage="file='close_p.png'"/> </HorizontalLayout></HorizontalLayout><VerticalLayout name="body" padding="10,10,2,2"><Text name="text_str" wordbreak="true" text="安能摧眉折腰事权贵,使我不得开心颜" fontColor="0xFF333333" textPadding="5,5,5,5"/><Control height="10" /><Edit name="edit_str" width="120" height="26" textpadding="1,1,1,1" bkcolor="#FFFAEBD7"/><Control height="10" /><Button name="btn_test" text="测试" height="30" width="120" normalimage="file='button.png'" hotimage="file='button_h.png'" pushedimage="file='button_p.png'"/> </VerticalLayout></VerticalLayout>
</Window>

其中资源文件:

事件处理:

notify函数代码如下:

// 核心功能:控件事件分发、消息传递枢纽
void Notify(TNotifyUI& msg)
{if (msg.sType == _T("click")) {//if (msg.pSender->GetName() == _T("I服了You")) { // 即点击的根控件root,代码见下面//    Close(); // 关闭窗口//}if (msg.pSender->GetName() == _T("closebtn")) { // 点击关闭窗口Close();} else if (msg.pSender->GetName() == _T("minbtn")) { // 最小化//ShowWindow(m_hWnd, SW_MINIMIZE); // 不起作用::ShowWindow(m_hWnd, SW_MINIMIZE); // 通过全局作用域符强制调用Win32 API函数}else if (msg.pSender->GetName() == _T("maxbtn")) { // 最大化::ShowWindow(m_hWnd, SW_MAXIMIZE);// 隐藏最大化按钮CButtonUI* maxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));if (maxBtn) {maxBtn->SetVisible(false);}// 显示恢复按钮CButtonUI* restoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));if (restoreBtn) {restoreBtn->SetVisible(true);}}else if (msg.pSender->GetName() == _T("restorebtn")) { // 恢复::ShowWindow(m_hWnd, SW_RESTORE);CControlUI* restoreBtn = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));if (restoreBtn) restoreBtn->SetVisible(false);CControlUI* maxBtn = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));if (maxBtn) maxBtn->SetVisible(true);} else if (msg.pSender->GetName() == _T("btn_test")) {// 测试读取输入框文本:CEditUI* editStr = static_cast<CEditUI*>(m_pm.FindControl(_T("edit_str")));if (editStr) {CDuiString strText = editStr->GetText(); // 获取文本内容CTextUI* textStr = static_cast<CTextUI*>(m_pm.FindControl(_T("text_str")));if (textStr) textStr->SetText(strText); // 刷新文本组件// 测试显示消息盒MessageBox(m_hWnd, L"安能摧眉折腰事权贵,使我不得开心颜!", L"消息标题", MB_OK | MB_ICONINFORMATION);}}}
}

运行:

随意输入点文本,比如“老顽童”,点击测试按钮:

ok.  测试了右上角最小化、最大化、恢复的按钮功能也ok. 但是窗口不能用鼠标拖动,后面有时间再看下。

http://www.dtcms.com/a/329157.html

相关文章:

  • C语言零基础第15讲:字符函数和字符串函数
  • ThinkPHP+Mysql 灵活用工小程序-技术深度解析与实践指南
  • 对线面试官之幂等和去重
  • 数据结构:用数组实现队列(Implementing Queue Using Array)
  • vue修改element的css属性
  • Docker端口映射完全指南:打通容器内外通信的关键技术
  • 如何把ubuntu 22.04下安装的mysql 8 的 数据目录迁移到另一个磁盘目录
  • 从“存得对”到“存得准”:MySQL 数据类型与约束全景指南
  • MySQL中的缓存机制
  • 浅谈TLS 混合密钥交换:后量子迁移过渡方案
  • openMVG---安装openMVG
  • C++主流string的使用
  • Linux内核的递归熵与异步系统守护进程的耦合解
  • 【类与对象(下)】探秘C++构造函数初始化列表
  • ROS机器人云实践案例设计
  • Git核心机制:工作区、暂存区与版本库
  • PG靶机 - Pelican
  • 【龙泽科技】汽车故障诊断仿真教学软件【科鲁兹】
  • (vue)el-table动态合并最后一行且内容靠左
  • CSS 多列布局(Multi-column Layout):快速上手指南
  • 基于UniApp的智能在线客服系统前端设计与实现
  • AI驱动的前端革命:10项颠覆性技术如何在LibreChat中融为一体
  • 3.9开发前端常用的几个工具(nvm,json-server,nrm)
  • vue实现模拟 ai 对话功能
  • C++QT HTTP与HTTPS的使用方式
  • Vue3从入门到精通:4.1 Vue Router 4深度解析与实战应用
  • 当GitHub宕机时,我们如何保持高效协作?分布式策略与应急方案详解
  • 将C#/.net项目附加到进程中
  • mac下载maven并配置,以及idea配置
  • 为什么要使用消息队列呢?