duilib自定义组件
1、先定义类
class CDetectInfoListUI : public CListUI, public IListCallbackUI
2、xml里引用
<HorizontalLayout bkcolor="#FFE1E1E1" childpadding="10"> <DetectInfoList bkcolor="#FFEAEAEA" bordersize="1" padding="30,10,10,10" bordercolor="#FFBABABA" width="400" height="400" name="myList" itemshowhtml="true" VScrollBar="true" HScrollBar="true"/> </HorizontalLayout>
3、引用,重要:
class CFrameWindowWnd : public CWindowWnd, public INotifyUI, public IDialogBuilderCallback
virtual CControlUI* CreateControl(LPCTSTR pstrClass); CControlUI* CFrameWindowWnd::CreateControl(LPCTSTR pstrClass) { if (_tcsicmp(pstrClass, _T("DetectInfoList")) == 0) { return (m_pInfoList = new CDetectInfoListUI); } return NULL; }
引用xml的窗体里必须要继承接口IDialogBuilderCallback,并实现里面的CreateControl,才能解析到这个控件
然后在OnPrepare里就能用了。