zoukankan      html  css  js  c++  java
  • 2021 Duilib最新入门教程(七)Duilib处理消息

    前言

      在前面有提到:使用Duilib编写一个界面软件,本质上还是一个Win32的软件,只不过这个软件的界面不使用Windows自带的控件,而是交给Duilib绘制界面。
      关于消息处理,底层还是处理Window消息,但Duilib会进一步转化成Duilib消息,方便编写响应的逻辑。
      

    例子

    // 界面上显示一个按钮 按钮名字为btn
    <Button name="btn" text="按钮" />
    
    // 点击按钮,会激活按钮控件,然后产生消息:DUI_MSGTYPE_CLICK
    bool CButtonUI::Activate()
    {
    	if( !CControlUI::Activate() ) return false;
    	if( m_pManager != NULL ) 
            m_pManager->SendNotify(this, DUI_MSGTYPE_CLICK);
    	return true;
    }
    
    // 处理消息 重写INotifyUI::Notify
    virtual void Notify(TNotifyUI& msg) 
    {
            // 处理Duilib点击消息 DUI_MSGTYPE_CLICK
    	if (msg.sType == DUI_MSGTYPE_CLICK)	
    	{
                    // 判断是否是btn按钮
    		if (msg.pSender->GetName() == _T("btn"))
    		{
    			::MessageBox(NULL, _T("按钮内容"), _T("按钮标题"), NULL);
    		}
    	}
    }
    

      

    小结

      Duilib处理消息,是在Notify函数里面进行处理:先判断Duilib消息类型,再判断是哪个控件,最后做出消息处理对应的操作。
      
    Duilib技术交流群:799142530
    源码地址:https://github.com/KongKong20/DuilibTutor

  • 相关阅读:
    LeetCode:Remove Duplicates from Sorted List
    LeetCode:Remove Nth Node From End of List
    LeetCode:Delete Node in a Linked List
    LeetCode:Rotate Image
    LeetCode:Anagrams(字母颠倒)
    LeetCode:Single NumberⅡ
    LeetCode:Single Number
    LeetCode:Longest Common Prefix
    bzoj1025
    bzoj1024
  • 原文地址:https://www.cnblogs.com/wwgk/p/14320492.html
Copyright © 2011-2022 走看看