zoukankan      html  css  js  c++  java
  • duilib学习笔记03:Duilib中的事件响应的两种方式

    Duilib中的事件响应有两种方式:


    ★:在事件处理类(一般使用窗口类)中实现INotifyUI接口,然后在Notify函数中处理事件,这种方式比较简单常用。

    class CLoginFrameWnd : public CWindowWnd, public INotifyUI
    {
        public:
            // ……
            void Notify(TNotifyUI& msg)
            {
                if( msg.sType == _T("click") )
                {
                    if( msg.pSender->GetName() == _T("closebtn") )
                    {
                        PostQuitMessage(0); return;
                    }
                    else if( msg.pSender->GetName() == _T("loginBtn") )
                    {
                        Close();
                        return;
                    }
                }
                else if( msg.sType == _T("itemselect") )
                {
                    if( msg.pSender->GetName() == _T("accountcombo") )
                    {
                        CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
                        if( pAccountEdit )
                        {
                            pAccountEdit->SetText(msg.pSender->GetText());
                        }
                    }
                }
            }
    }

    --------------------------------------------------------------------------------

    ★:使用代理机制处理事件

    class CLoginFrameWnd : public CWindowWnd, public INotifyUI
    {
        public:
            // ……
            bool OnAlphaChanged(void* param) {
                TNotifyUI* pMsg = (TNotifyUI*)param;
                if( pMsg->sType == _T("valuechanged") )
                {
                    m_pm.SetTransparent((static_cast<CSliderUI*>(pMsg->pSender))->GetValue());
                }
    
                return true;
            }
    
            // 需要在控件创建完成之后调用.
            void OnPrepare() 
            {
                CSliderUI* pSilder = static_cast<CSliderUI*>(m_pm.FindControl(_T("alpha_controlor")));
                if( pSilder )
                {
                    pSilder->OnNotify += MakeDelegate(this, &CFrameWindowWnd::OnAlphaChanged);
                }
            }
    }

    --------------------------------------------------------------------------------

  • 相关阅读:
    线性DP
    2020年第十一届蓝桥杯第二场C/C++ B组省赛题解
    筛质数 + 质因子分解
    快速幂
    DP 背包问题
    CF510B Fox And Two Dots
    怎样看人生的价值和意义!--找回迷失的自己
    Ionic+AngularJS 开发的页面在微信公众号下显示不出来原因查究
    AngularJS directive 指令相关记录
    AngularJS的一点学习笔记
  • 原文地址:https://www.cnblogs.com/xuejianhui/p/2782884.html
Copyright © 2011-2022 走看看