ListBoxDlg.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // ListBoxDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Control.h"
  5. #include "ListBoxDlg.h"
  6. // CListBoxDlg 对话框
  7. IMPLEMENT_DYNAMIC(CListBoxDlg, CDlgControlItem)
  8. CListBoxDlg::CListBoxDlg(CWnd* pParent /*=NULL*/)
  9. : CDlgControlItem(CListBoxDlg::IDD, pParent)
  10. {
  11. }
  12. CListBoxDlg::~CListBoxDlg()
  13. {
  14. }
  15. void CListBoxDlg::DoDataExchange(CDataExchange* pDX)
  16. {
  17. CDlgControlItem::DoDataExchange(pDX);
  18. DDX_Control(pDX,IDC_LIST1,m_ListBox);
  19. DDX_Control(pDX,IDC_LIST2,m_ListBox2);
  20. }
  21. BEGIN_MESSAGE_MAP(CListBoxDlg, CDlgControlItem)
  22. ON_BN_CLICKED(IDC_BUTTON1, &CListBoxDlg::OnBnClickedButton1)
  23. ON_BN_CLICKED(IDC_BUTTON14, &CListBoxDlg::OnBnClickedButton14)
  24. ON_BN_CLICKED(IDC_BUTTON16, &CListBoxDlg::OnBnClickedButton16)
  25. ON_BN_CLICKED(IDC_BUTTON17, &CListBoxDlg::OnBnClickedButton17)
  26. ON_BN_CLICKED(IDC_BUTTON15, &CListBoxDlg::OnBnClickedButton15)
  27. ON_BN_CLICKED(IDC_BUTTON18, &CListBoxDlg::OnBnClickedButton18)
  28. ON_BN_CLICKED(IDC_BUTTON2, &CListBoxDlg::OnBnClickedButton2)
  29. ON_BN_CLICKED(IDC_BUTTON3, &CListBoxDlg::OnBnClickedButton3)
  30. ON_BN_CLICKED(IDC_BUTTON4, &CListBoxDlg::OnBnClickedButton4)
  31. ON_RBN_DBLCLK(IDC_LIST1, &CListBoxDlg::OnRbnDblclkList1)
  32. ON_RBN_DBLCLK(IDC_LIST2, &CListBoxDlg::OnRbnDblclkList2)
  33. END_MESSAGE_MAP()
  34. // CListBoxDlg 消息处理程序
  35. BOOL CListBoxDlg::OnInitDialog()
  36. {
  37. CDlgControlItem::OnInitDialog();
  38. m_ListBox.SetBackNormalImage(TEXT("Res\\Edit\\frameBorderEffect_mouseDownDraw.png"),CRect(3,3,3,3));
  39. m_ListBox.SetSelectImage(TEXT("Res\\ComboBox\\listitem_select.png"),CRect(3,3,3,3));
  40. m_ListBox.SetHovenImage(TEXT("Res\\ListBox\\highlight.png"),CRect(3,3,3,3));
  41. m_ListBox2.SetBackNormalImage(TEXT("Res\\Edit\\frameBorderEffect_mouseDownDraw.png"),CRect(3,3,3,3));
  42. m_ListBox2.SetSelectImage(TEXT("Res\\ComboBox\\listitem_select.png"),CRect(3,3,3,3));
  43. m_ListBox2.SetHovenImage(TEXT("Res\\ListBox\\highlight.png"),CRect(3,3,3,3));
  44. m_ListBox2.SetScrollImage(&m_ListBox2,TEXT("Res\\Scroll\\SKIN_SCROLL.bmp"));
  45. m_ListBox2.AddString(TEXT("我的好友"));
  46. m_ListBox2.AddString(TEXT("MFC"));
  47. m_ListBox2.AddString(TEXT("C++"));
  48. m_ListBox2.AddString(TEXT("VC"));
  49. m_ListBox2.AddString(TEXT("C#"));
  50. m_ListBox2.AddString(TEXT("陌生人"));
  51. m_ListBox2.AddString(TEXT("Dephi"));
  52. m_ListBox2.AddString(TEXT("python"));
  53. m_ListBox2.AddString(TEXT("Lua"));
  54. m_ListBox2.AddString(TEXT("java"));
  55. for (int i=1;i<m_ListBox2.GetCount();i++)
  56. {
  57. if ( i==5) continue;
  58. m_ListBox2.SetItemHeight(i,50);
  59. }
  60. return TRUE; // return TRUE unless you set the focus to a control
  61. // 异常: OCX 属性页应返回 FALSE
  62. }
  63. void CListBoxDlg::OnBnClickedButton1()
  64. {
  65. static int i=0;
  66. CString str;
  67. str.Format(TEXT("Item_%d"),++i);
  68. m_ListBox.AddString(str);
  69. m_ListBox.SetItemHeight(1,40);
  70. }
  71. void CListBoxDlg::OnBnClickedButton14()
  72. {
  73. for (int i=m_ListBox.GetCount();i>=0;i--)
  74. {
  75. if ( m_ListBox.GetSel(i) )
  76. {
  77. m_ListBox.DeleteString(i);
  78. }
  79. }
  80. }
  81. void CListBoxDlg::OnBnClickedButton16()
  82. {
  83. CString str=TEXT("当前选中的节点依次为:"),strTemp;
  84. for (int i=0;i<m_ListBox.GetCount();i++)
  85. {
  86. if ( m_ListBox.GetSel(i) )
  87. {
  88. strTemp.Format(TEXT("[ %d ]"),i);
  89. str+=strTemp;
  90. }
  91. }
  92. MessageBox(str);
  93. }
  94. void CListBoxDlg::OnBnClickedButton17()
  95. {
  96. CString str;
  97. str.Format(TEXT("选中节点的数量有 %d 个"),m_ListBox.GetSelCount());
  98. MessageBox(str);
  99. }
  100. void CListBoxDlg::OnBnClickedButton15()
  101. {
  102. CString str;
  103. str.Format(TEXT("节点的总数量为 %d 个"),m_ListBox.GetCount());
  104. MessageBox(str);
  105. }
  106. void CListBoxDlg::OnBnClickedButton18()
  107. {
  108. CString str=TEXT("当前选中的节点的文本依次为:"),strTemp,strItem;
  109. for (int i=0;i<m_ListBox.GetCount();i++)
  110. {
  111. if ( m_ListBox.GetSel(i) )
  112. {
  113. m_ListBox.GetText(i,strItem);
  114. strTemp.Format(TEXT("[ %s ]"),strItem);
  115. str+=strTemp;
  116. }
  117. }
  118. MessageBox(str);
  119. }
  120. void CListBoxDlg::OnBnClickedButton2()
  121. {
  122. CString str,strTemp,strItem=TEXT("查找的字符串匹配项分别为:");
  123. GetDlgItemText(IDC_EDIT1,str);
  124. bool bHave = false;
  125. for (int i=0;i<m_ListBox.GetCount();i++)
  126. {
  127. if( m_ListBox.FindStringExact(i,str)!= LB_ERR )
  128. {
  129. bHave = true;
  130. strTemp.Format(TEXT("[ %d ]"),i);
  131. strItem+=strTemp;
  132. }
  133. }
  134. if(bHave)
  135. MessageBox(strItem);
  136. else MessageBox(TEXT("没有合适的匹配项"));
  137. }
  138. void CListBoxDlg::OnBnClickedButton3()
  139. {
  140. CString str,strTemp,strItem=TEXT("查找的字符串匹配项分别为:");
  141. GetDlgItemText(IDC_EDIT1,str);
  142. bool bHave = false;
  143. for (int i=0;i<m_ListBox.GetCount();i++)
  144. {
  145. if( m_ListBox.SelectString(i,str)!= LB_ERR )
  146. {
  147. bHave = true;
  148. strTemp.Format(TEXT("[ %d ]"),i);
  149. strItem+=strTemp;
  150. }
  151. }
  152. if(bHave)
  153. MessageBox(strItem);
  154. else MessageBox(TEXT("没有合适的匹配项"));
  155. }
  156. void CListBoxDlg::OnBnClickedButton4()
  157. {
  158. OpenLink(TEXT("http://www.gymsaga.com/project/444.html"));
  159. }
  160. void CListBoxDlg::OnRbnDblclkList1()
  161. {
  162. CString str;
  163. str.Format(TEXT("选中的节点为:%d"),m_ListBox.GetCurSel());
  164. MessageBox(str);
  165. }
  166. void CListBoxDlg::OnRbnDblclkList2()
  167. {
  168. CString str;
  169. str.Format(TEXT("选中的节点为:%d"),m_ListBox2.GetCurSel());
  170. MessageBox(str);
  171. }