关闭

duilib 如果获取listui 当前选择的项GetCursel

标签: duilibListUi当前选择的项GetCursel
849人阅读 评论(0) 收藏 举报
分类:
<pre name="code" class="cpp">class CDuiFrameWnd : public WindowImplBase
{
public:
	virtual LPCTSTR    GetWindowClassName() const   {   return _T("DUIMainFrame");  }
	virtual CDuiString GetSkinFile()                {   return _T("duilib1.xml");  }
	virtual CDuiString GetSkinFolder()              {   return _T("");  }

	virtual void  InitWindow()
	{

		CDuiString str;
		CListUI* pList = static_cast<CListUI*>(m_PaintManager.FindControl(_T("ListDemo1")));

		// 添加List列表内容,必须先Add(pListElement),再SetText
		for (int i = 0; i < 5; i++)
		{
			CListTextElementUI* pListElement = new CListTextElementUI;
			pListElement->SetTag(i);
			pList->Add(pListElement);

			str.Format(_T("%d"), i);
			pListElement->SetText(0, str);
			pListElement->SetText(1, _T("haha"));
		}
	}

	void Notify(TNotifyUI& msg)
	{
		if (msg.sType == _T("itemclick"))
		{
				CListUI* pList = static_cast<CListUI*>(m_PaintManager.FindControl(_T("ListDemo1")));
				if (pList != NULL)
				{
					int nIndex  = pList->GetCurSel();
					//对于列表框大于2列的情况 用以下方式进行获取两列的值 和进行设置
					//切记 列表框初始化的时候 一定要两列都初始化,否则SetText函数会执行失败
					//如果有大于2列的列表框,xml资源里面切记不要
					/*
					<List name="ListDemo1" float="true" pos="30,314,0,0" width="139" height="218" bkcolor="#FFFFFFFF" itemtextcolor="#FF000000" itembkcolor="#FFE2DDDF" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" >
					<ListHeader name="domain" bkimage="List/list_header_bg.png">
					<ListHeaderItem text="序号" width="40" height="23" minwidth="16"  sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
					<ListHeaderItem text="文件名称" width="84" height="23" minwidth="16"  sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
					</ListHeader>
					<ListLabelElement text="张三1" selected="true" />
					<ListLabelElement text="李四2" />不要这样写 
					否则会导致 pListElement->SetText(0,_T("test1"));pListElement->SetText(1,_T("test2"));执行失败 切记!!!!!
					正确的做法是 将ListLabelElement 初始化去掉 在InitWindow 里面初始化 
					</List>
					*/
					CListTextElementUI* pListElement = static_cast<CListTextElementUI*>(pList->GetItemAt(nIndex));
					if (pListElement != NULL)
					{
						LPCTSTR pstr1 = pListElement->GetText(0);
						LPCTSTR pstr2 = pListElement->GetText(1);

						pListElement->SetText(0,_T("test1"));
						pListElement->SetText(1,_T("test2"));
					}
				}
		}
		return __super::Notify(msg);
	}

 };

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	HRESULT Hr = ::CoInitialize(NULL);
	if( FAILED(Hr) ) return 0;


	CPaintManagerUI::SetInstance(hInstance);

	CDuiFrameWnd duiFrame;
	duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
	duiFrame.CenterWindow();
	duiFrame.ShowModal();
	CPaintManagerUI::MessageLoop();
	::CoUninitialize();
	return 0;
}


//xml配置如下:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="700,400" caption="0,0,0,30">
    <HorizontalLayout width="400" height="400" bkcolor="#FF0000FF" bkcolor2="#00FF00FF" bordercolor="#00808000" focusbordercolor="#00008080">
      <List name="ListDemo1" float="true" pos="30,314,0,0" width="139" height="218" bkcolor="#FFFFFFFF" itemtextcolor="#FF000000" itembkcolor="#FFE2DDDF" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" >
        <ListHeader name="domain" bkimage="List/list_header_bg.png">
          <ListHeaderItem text="序号" width="40" height="23" minwidth="16"  sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
          <ListHeaderItem text="文件名称" width="84" height="23" minwidth="16"  sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
        </ListHeader>
      </List>
      
    </HorizontalLayout>
</Window>



   
2
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:133187次
    • 积分:2286
    • 等级:
    • 排名:第16454名
    • 原创:86篇
    • 转载:27篇
    • 译文:14篇
    • 评论:3条