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

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(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(m_PaintManager.FindControl(_T("ListDemo1")));
				if (pList != NULL)
				{
					int nIndex  = pList->GetCurSel();
					//对于列表框大于2列的情况 用以下方式进行获取两列的值 和进行设置
					//切记 列表框初始化的时候 一定要两列都初始化,否则SetText函数会执行失败
					//如果有大于2列的列表框,xml资源里面切记不要
					/*
					
					
					
					
					
					
					不要这样写 
					否则会导致 pListElement->SetText(0,_T("test1"));pListElement->SetText(1,_T("test2"));执行失败 切记!!!!!
					正确的做法是 将ListLabelElement 初始化去掉 在InitWindow 里面初始化 
					
					*/
					CListTextElementUI* pListElement = static_cast(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配置如下:


    
      
        
          
          
        
      
      
    



 
 

你可能感兴趣的:(duilib开源界面库)