MFC之CListBox、CListCtrl

This blog briefly introduces the use of CListBox and CListCtrl tools.

Use the MFC wizard to create a dialog program, add a CListBox and CListCtrl resource to the dialog box in the resource editing window and associate a control object.


Add the following code to the member function OnInitDialog

[cpp]  view plain  copy
  1. CRect rect;  
  2. GetClientRect(&rect);  
  3.   
  4.        //The selected item is highlighted and grid lines are drawn  
  5. m_listctrl.SetExtendedStyle(m_listctrl.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);  
  6.        //Create 3 column objects  
  7. m_listctrl.InsertColumn(0,"语言",LVCFMT_LEFT,70);         
  8. m_listctrl.InsertColumn(1,"2010排名",LVCFMT_LEFT,70);  
  9. m_listctrl.InsertColumn(2,"2011排名",LVCFMT_LEFT,70);  
  10.   
  11. m_listctrl.InsertItem(0, "java" );     //Create a row object  
  12. m_listctrl.SetItemText(0,1, "1" );     //Create child object members  
  13. m_listctrl.SetItemText(0,2,"2");  
  14.   
  15. m_listctrl.InsertItem(1,"c++");  
  16. m_listctrl.SetItemText(1,1,"3");  
  17. m_listctrl.SetItemText(1,2,"3");  
  18.   
  19. m_listctrl.InsertItem(2,"c");  
  20. m_listctrl.SetItemText(2,1,"2");  
  21. m_listctrl.SetItemText(2,2,"1");  
  22.   
  23.   
  24. m_listbox.AddString("string one");  
  25. m_listbox.AddString("string two");  
  26. m_listbox.AddString("string three");  

Click Run to see the initialized data in the control.

Reprinted from: http://blog.csdn.net/gk_2014/article/details/46353189


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325866037&siteId=291194637