天天看點

Duilib在控件中包含xml的兩種方法

方法一:

在xml中使用Include,具體代碼如下

<Container>

        <Include source="abc.xml"/>

</Container>

方法二:

自定義控件

1、将上面的xml替換成下面的樣式

<Container>

        <MyAbc />

</Container>

2、建立CMyAbcUI類,繼承至CContainerUI類。

3、重寫DoInit函數,在函數内部利用建構器建立,代碼如下:

void CCrossTextUI::DoInit()

{

    CDialogBuilder builder;

    CContainerUI* pMyAbc = static_cast<CContainerUI*>(builder.Create(_T("MyAbc.xml"), (UINT)0));

    if(pMyAbc )

        this->Add(pMyAbc );

    else

    {

        this->RemoveAll();

        return ;

    }

}

繼續閱讀