经过前面的小节部分,已经讲解了大部分的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<CPaintManagerUI*>(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成员内部。

  欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发和插件定制开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com.
公司网址:http://www.zhiliaos.com

本文地址:https://blog.csdn.net/weixin_42247427/article/details/107279439