DuiLib响应按钮事件
2015-09-08 16:42
225 查看
配置方法以及需要重写的函数已经在在《初识DuiLib界面库》中已经介绍。
今天需要在之前代码的基础上加入相应Enter按钮的事件,并弹出messagebox按钮。
响应事件在Notify函数中进行处理。
运行截图如下:
这里有一个问题,当我们点击窗口的关闭按钮后,窗口被关闭了,但是MessageBox窗口依然存在。这是为什么呢?
今天需要在之前代码的基础上加入相应Enter按钮的事件,并弹出messagebox按钮。
响应事件在Notify函数中进行处理。
#include "UIlib.h" using namespace DuiLib; # pragma comment(lib, "DuiLib_d.lib") # pragma comment(lib, "DuiLib.lib") class CDuiFrameWnd : public CWindowWnd, public INotifyUI { public: virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); } virtual void Notify(TNotifyUI& msg) { if(msg.sType == _T("click")) { if (msg.pSender->GetName() == _T("btnHello")) { ::MessageBox(NULL, _T("我是按钮"), _T("点击了按钮"), NULL); } } } virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT lRes = 0; if( uMsg == WM_CREATE ) { CControlUI *pWnd = new CButtonUI;//CControlUI是duilib中所有空间的基类 pWnd->SetName(_T("btnHello")); // 设置控件的名称,这个名称用于标识每一个控件,必须 唯一,相当于MFC里面的控件ID pWnd->SetText(_T("Hello World")); // 设置文字 pWnd->SetBkColor(0xFF00FFFF); // 设置背景色 m_PaintManager.Init(m_hWnd); m_PaintManager.AttachDialog(pWnd); m_PaintManager.AddNotifier(this); // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理 return lRes; } if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) { return lRes; } return __super::HandleMessage(uMsg, wParam, lParam); } protected: CPaintManagerUI m_PaintManager; }; 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.ShowModal(); return 0; }
运行截图如下:
这里有一个问题,当我们点击窗口的关闭按钮后,窗口被关闭了,但是MessageBox窗口依然存在。这是为什么呢?
相关文章推荐
- DuiLib响应按钮事件
- easyUI的行内编辑editor
- iOS UIActivityIndicatorView
- UI 设计师提供 iOS 字体和长度应当用什么单位
- UITableViewCell与cell之间的那条线
- StringBuilder与StringBuffer的区别(转)
- easyUI中的datagrid的formatter方法中 使用$.ajax()方法绑定多个不同数据源的数据
- DelayQueue Demo
- NYOJ 686 An Interesting Sequence 【欧拉函数】
- 十大滤波算法程序大全(Arduino精编无错版)(转)
- The server quit without updating PID file (/var/run/mysqld/mysqld.pid). ...
- Reinstall the Arduino Pro Mini Bootloade ISP(转)
- Arduino中hex文件的保存及应用(转)
- Arduino单片机使用和开发问题记录(转)
- UDK: Lightmap UV Layout Techniques & How to Create a Second UV Channel in Maya
- UILabel根据内容自动调整高度
- leetCode #96 Unique Binary Search Trees
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
- 更改UIImage颜色
- iOS小结(四) GPUImage加速图像处理