动态创建list控件

下边是windows 下使用duilibui库动态创建list的代码片段,不需要xml中预先写入控件,只需要有一个容器即可。
		CListUI *list = new CListUI();// static_cast(m_PaintManager.FindControl(_T("MainFrame_ModeSelectList")));
		CHorizontalLayoutUI* pLayoutUI = static_cast (m_PaintManager.FindControl(_T("MainFrame_CameraAndColor")));
		/*List name="MainFrame_ModeSelectList" bkcolor="#FFFFFFFF" float="true" inset="0,0,0,0" scrollselect="false" itemshowhtml="false" pos="560,500,0,0" visible ="false" 
		width="200" height="200" vscrollbar="true" bkimage="yCat_2_10_29.png" header="hidden" itemalign="center" itembkcolor="#FFE2DDDF" itemaltbk="true" itemlinecolor="#0000FF00" menu="false">*/
		RECT rc;		
		RECT rc2 = {0};


		isFirstTime = false;			
		rc2.left = (rc.right - rc.left - 200) / 2 + rc.left;
		rc2.right = rc2.left + 200;
		rc2.top = (rc.bottom - rc.top - 32 * 2) / 2 + rc.top;
		rc2.bottom = rc2.top + 32*2;


		list->SetName(_T("MainFrame_CommonList"));
		list->SetAttribute(_T("float"), _T("true"));
		list->SetAttribute(_T("bkcolor"), _T("#FFFFFFFF"));
		list->SetAttribute(_T("roundcorner"), _T("5,5"));
		list->SetAttribute(_T("scrollselect"), _T("false"));
		list->SetAttribute(_T("vscrollbar"), _T("true"));
		list->SetAttribute(_T("bkimage"), _T("yCat_2_10_29.png"));
		list->SetAttribute(_T("itembkcolor"), _T("#FFE2DDDF"));
		list->SetAttribute(_T("itemaltbk"), _T("true"));
		list->SetAttribute(_T("itemshowhtml"), _T("false"));
		list->SetAttribute(_T("inset"), _T("0,0,0,0"));
		list->SetAttribute(_T("header"), _T("hidden"));
		list->SetAttribute(_T("itemalign"), _T("center"));
		list->SetAttribute(_T("menu"), _T("false"));	


		list->SetBkImage(_T("yCat_2_10_29.png"));
		list->SetItemFont(3);
		list->SetItemBkImage(_T("yCat_2_10_26.png"));
		list->SetSelectedItemImage(_T("yCat_2_10_26.png"));
		list->SetHotItemImage(_T("yCat_2_10_26.png"));
			
		CListLabelElementUI *item = new CListLabelElementUI();
		list->Add(item);
		item->SetText(_T("白天"));
		CListLabelElementUI *item2 = new CListLabelElementUI();
		list->Add(item2);
		item2->SetText(_T("黑夜"));
		pLayoutUI->Add(list);
		list->SetPos(rc2);//setpos要放到后面来,可能是因为pos是相对位置。
		pLayoutUI->NeedUpdate();		
		list->SetVisible(true);

你可能感兴趣的:(Duilib)