您当前的位置: 首页 >  ui

插件开发

暂无认证

  • 1浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

第一章 第六小节Duilib的WindowImplBase基类OnCreate函数中调用AttachDialog函数

插件开发 发布时间:2022-03-26 09:27:25 ,浏览量:1

文章目录
    • 1.CDialogBuilder对象中AttachDialog函数
    • 2.作者答疑

1.CDialogBuilder对象中AttachDialog函数

  经过前面的小节部分,已经讲解了大部分的OnCreate函数,最后一个关键函数是AttachDialog函数,它进行着CPaintManagerUI成员部分重新初始化操作,如阴影的构建、将根控件指针保存至CPaintManagerUI内部和对根控件进行再次的初始化等,源码如下:

    bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
    {
        ASSERT(::IsWindow(m_hWndPaint));
        // 创建阴影窗口
        m_shadow.Create(this);

        // Reset any previous attachment
        SetFocus(NULL);
        m_pEventKey = NULL;
        m_pEventHover = NULL;
        m_pEventClick = NULL;
        // Remove the existing control-tree. We might have gotten inside this function as
        // a result of an event fired or similar, so we cannot just delete the objects and
        // pull the internal memory of the calling code. We'll delay the cleanup.
        if( m_pRoot != NULL ) {
            m_aPostPaintControls.Empty();
            AddDelayedCleanup(m_pRoot);
        }
        // Set the dialog root element
        m_pRoot = pControl;
        // Go ahead...
        m_bUpdateNeeded = true;
        m_bFirstLayout = true;
        m_bFocusNeeded = true;
        // Initiate all control
        return InitControls(pControl);//其中将根控件按名字注册到m_mNameHash内,下小节
    }
    
    bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
    {
        ASSERT(pControl);
        if( pControl == NULL ) return false;
        pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
        pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);//注册控件
        return true;
    }
    
    CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
    {
        CPaintManagerUI* pManager = static_cast(pData);
        const CDuiString& sName = pThis->GetName();
        if( sName.IsEmpty() ) return NULL;
        // Add this control to the hash list
        pManager->m_mNameHash.Set(sName, pThis);//注册控件到m_mNameHash内
        return NULL; // Attempt to add all controls
    }

  至此继承至WindowImplBase基类的窗口基本讲解完毕,回顾一下,其实很简单,首先设置模块的句柄,根据模块的句柄获取资源(图片,xml)所在位置,然后设置窗口的属性,最后解析xml文件,生成控件树并填充属性,并将根节点绑定到CPaintManagerUI成员内部。

2.作者答疑

  如有疑问,请留言。

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0421s