当前位置: 首页 > 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.lryc.cn/news/619667.html

相关文章:

  • 基于UniApp的新大陆物联网平台温湿度检测系统开发方案
  • 在JVM跑JavaScript脚本 | Oracle GraalJS 简介与实践
  • 【AI论文】GLM-4.5:具备智能体特性、推理能力与编码能力的(ARC)基础模型
  • Avalon-MM协议
  • 浅层神经网络
  • SimD小目标样本分配方法
  • 开发避坑指南(24):RocketMQ磁盘空间告急异常处理,CODE 14 “service not available“解决方案
  • 设计原则之【抽象层次一致性(SLAP)】,方法也分三六九等
  • 从零到一:TCP 回声服务器与客户端的完整实现与原理详解
  • Linux LNMP配置全流程
  • 机器学习之词向量转换
  • 第5章 学习的机制
  • 对比学习中核心损失函数的发展脉络
  • AI服务器需求激增,三星内存与SSD供不应求,HBM与DDR5成关键驱动力
  • 2025年高效能工程项目管理软件推荐榜单:AI重构工程进度可视化与资源动态调度体系
  • kernel pwn 入门(四) ret2dir详细
  • 《嵌入式Linux应用编程():Linux Framebuffer图形编程》
  • Win11和Mac设置环境变量
  • 机器学习阶段性总结:对深度学习本质的回顾 20250813
  • Html5-canvas动态渐变背景
  • mac 安卓模拟器 blueStacks
  • MacOS字体看起来比在 Windows 上更好?
  • 367. 有效的完全平方数
  • Spring Boot + MyBatis
  • Python 元类基础:从理解到应用的深度解析
  • [CSCCTF 2019 Qual]FlaskLight
  • [AI React Web] 包与依赖管理 | `axios`库 | `framer-motion`库
  • Spring cloud集成ElastictJob分布式定时任务完整攻略(含snakeyaml报错处理方法)
  • 使用TexLive与VScode排版论文
  • 从0开始配置conda环境并在PyCharm中使用