ListCtrlCl.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. // ListCtrlCl.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "ListCtrlCl.h"
  5. #include ".\listctrlcl.h"
  6. #define IDC_EDITB 4000
  7. #define IDC_BTN 5000
  8. #define IDC_COMB 6000
  9. struct stColor
  10. {
  11. int nRow;
  12. int nCol;
  13. COLORREF rgb;
  14. };
  15. // CListCtrlCl
  16. IMPLEMENT_DYNAMIC(CListCtrlCl, CListCtrl)
  17. CListCtrlCl::CListCtrlCl()
  18. : m_nRowHeight(0)
  19. , m_fontHeight(12)
  20. , m_fontWith(0)
  21. {
  22. m_color = RGB(0,0,0);
  23. InitializeCriticalSection(&m_SECTION);
  24. m_nRow=-1;
  25. m_nCol=-1;
  26. m_nRowOld=-1;
  27. m_nColOld=-1;
  28. m_nRowMin = 0;
  29. m_nRowMax = 99999;
  30. m_nColMin = 0;
  31. m_nColMax = 99999;
  32. memset( m_nItemType,0,100*4 );
  33. }
  34. CListCtrlCl::~CListCtrlCl()
  35. {
  36. for (POSITION pos = m_ptrListCol.GetHeadPosition();pos!=NULL;)
  37. {
  38. stColor *pColor = (stColor*)m_ptrListCol.GetNext(pos);
  39. delete pColor;
  40. pColor = NULL;
  41. }
  42. m_ptrListCol.RemoveAll();
  43. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  44. {
  45. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  46. delete pColor;
  47. pColor = NULL;
  48. }
  49. m_ptrListItem.RemoveAll();
  50. for (POSITION pos = m_colTextColor.GetHeadPosition();pos!=NULL;)
  51. {
  52. stColor *pColor = (stColor*)m_colTextColor.GetNext(pos);
  53. delete pColor;
  54. pColor = NULL;
  55. }
  56. m_colTextColor.RemoveAll();
  57. for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
  58. {
  59. stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
  60. delete pColor;
  61. pColor = NULL;
  62. }
  63. m_ItemTextColor.RemoveAll();
  64. DeleteCriticalSection( &m_SECTION );
  65. }
  66. BEGIN_MESSAGE_MAP(CListCtrlCl, CListCtrl)
  67. ON_WM_MEASUREITEM()
  68. ON_WM_MEASUREITEM_REFLECT()
  69. ON_NOTIFY_REFLECT(LVN_DELETEALLITEMS, OnLvnDeleteallitems)
  70. ON_WM_LBUTTONDOWN()
  71. ON_WM_KILLFOCUS()
  72. // ON_WM_DELETEITEM()
  73. ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnLvnDeleteitem)
  74. END_MESSAGE_MAP()
  75. // CListCtrlCl 消息处理程序
  76. void CListCtrlCl::PreSubclassWindow()
  77. {
  78. // TODO: 在此添加专用代码和/或调用基类
  79. ModifyStyle(0,LVS_OWNERDRAWFIXED);
  80. CListCtrl::PreSubclassWindow();
  81. CHeaderCtrl *pHeader = GetHeaderCtrl();
  82. m_Header.SubclassWindow(pHeader->GetSafeHwnd());
  83. }
  84. void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  85. {
  86. // TODO: 添加您的代码以绘制指定项
  87. //EnterCriticalSection( &m_SECTION );
  88. TCHAR lpBuffer[256];
  89. LV_ITEM lvi;
  90. lvi.mask = LVIF_TEXT | LVIF_PARAM ;
  91. lvi.iItem = lpDrawItemStruct->itemID ;
  92. lvi.iSubItem = 0;
  93. lvi.pszText = lpBuffer ;
  94. lvi.cchTextMax = sizeof(lpBuffer);
  95. VERIFY(GetItem(&lvi));
  96. LV_COLUMN lvc, lvcprev ;
  97. ::ZeroMemory(&lvc, sizeof(lvc));
  98. ::ZeroMemory(&lvcprev, sizeof(lvcprev));
  99. lvc.mask = LVCF_WIDTH | LVCF_FMT;
  100. lvcprev.mask = LVCF_WIDTH | LVCF_FMT;
  101. CDC* pDC;
  102. pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  103. CRect rtClient;
  104. GetClientRect(&rtClient);
  105. for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
  106. {
  107. if ( nCol > 0 )
  108. {
  109. // Get Previous Column Width in order to move the next display item
  110. GetColumn(nCol-1, &lvcprev) ;
  111. lpDrawItemStruct->rcItem.left += lvcprev.cx ;
  112. lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left;
  113. }
  114. CRect rcItem;
  115. if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))
  116. continue;
  117. ::ZeroMemory(&lvi, sizeof(lvi));
  118. lvi.iItem = lpDrawItemStruct->itemID;
  119. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  120. lvi.iSubItem = nCol;
  121. lvi.pszText = lpBuffer;
  122. lvi.cchTextMax = sizeof(lpBuffer);
  123. VERIFY(GetItem(&lvi));
  124. CRect rcTemp;
  125. rcTemp = rcItem;
  126. if (nCol==0)
  127. {
  128. rcTemp.left -=2;
  129. }
  130. if ( lpDrawItemStruct->itemState & ODS_SELECTED )
  131. {
  132. pDC->FillSolidRect(&rcTemp, RGB(86,159,255));//GetSysColor(COLOR_HIGHLIGHT)) ;
  133. pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
  134. }
  135. else
  136. {
  137. COLORREF color;
  138. color = GetBkColor();
  139. pDC->FillSolidRect(rcTemp,color);
  140. if (FindColColor(nCol,color))
  141. {
  142. pDC->FillSolidRect(rcTemp,color);
  143. }
  144. if (FindItemColor(nCol,lpDrawItemStruct->itemID,color))
  145. {
  146. pDC->FillSolidRect(rcTemp,color);
  147. }
  148. //pDC->SetTextColor(m_color);
  149. }
  150. pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
  151. UINT uFormat = DT_CENTER ;
  152. if (m_Header.m_Format[nCol]=='0')
  153. {
  154. uFormat = DT_LEFT;
  155. }
  156. else if (m_Header.m_Format[nCol]=='1')
  157. {
  158. uFormat = DT_CENTER;
  159. }
  160. else if (m_Header.m_Format[nCol]=='2')
  161. {
  162. uFormat = DT_RIGHT;
  163. }
  164. TEXTMETRIC metric;
  165. pDC->GetTextMetrics(&metric);
  166. int ofst;
  167. ofst = rcItem.Height() - metric.tmHeight;
  168. rcItem.OffsetRect(0,ofst/2);
  169. pDC->SetTextColor(m_color);
  170. COLORREF color;
  171. if (FindColTextColor(nCol,color))
  172. {
  173. pDC->SetTextColor(color);
  174. }
  175. if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color))
  176. {
  177. pDC->SetTextColor(color);
  178. }
  179. CFont nFont ,* nOldFont;
  180. nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体
  181. nOldFont = pDC->SelectObject(&nFont);
  182. DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
  183. &rcItem, uFormat) ;
  184. pDC->SelectStockObject(SYSTEM_FONT) ;
  185. DeleteObject( nFont );
  186. }
  187. //ReleaseDC( pDC );
  188. //LeaveCriticalSection( &m_SECTION );
  189. }
  190. void CListCtrlCl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  191. {
  192. // TODO: 在此添加消息处理程序代码和/或调用默认值
  193. CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  194. }
  195. void CListCtrlCl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  196. {
  197. if (m_nRowHeight>0)
  198. {
  199. lpMeasureItemStruct->itemHeight = m_nRowHeight;
  200. }
  201. }
  202. int CListCtrlCl::InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat /* = LVCFMT_LEFT */, int nWidth /* = -1 */, int nSubItem /* = -1 */)
  203. {
  204. m_Header.m_HChar.Add(lpszColumnHeading);
  205. if (nFormat==LVCFMT_LEFT)
  206. {
  207. m_Header.m_Format = m_Header.m_Format + "0";
  208. }
  209. else if (nFormat==LVCFMT_CENTER)
  210. {
  211. m_Header.m_Format = m_Header.m_Format + "1";
  212. }
  213. else if (nFormat==LVCFMT_RIGHT)
  214. {
  215. m_Header.m_Format = m_Header.m_Format + "2";
  216. }
  217. else
  218. {
  219. m_Header.m_Format = m_Header.m_Format + "1";
  220. }
  221. return CListCtrl::InsertColumn(nCol,lpszColumnHeading,nFormat,nWidth,nSubItem);
  222. }
  223. // Gradient - 渐变系数,立体背景用,不用渐变设为0
  224. void CListCtrlCl::SetHeaderBKColor(int R, int G, int B, int Gradient) //设置表头背景色
  225. {
  226. m_Header.m_R = R;
  227. m_Header.m_G = G;
  228. m_Header.m_B = B;
  229. m_Header.m_Gradient = Gradient;
  230. }
  231. // 设置表头高度
  232. void CListCtrlCl::SetHeaderHeight(float Height) //设置表头高度
  233. {
  234. m_Header.m_Height = Height;
  235. }
  236. bool CListCtrlCl::FindColColor(int col,COLORREF &color) //查找列颜色
  237. {
  238. //EnterCriticalSection( &m_SECTION );
  239. int flag = 0;
  240. for (POSITION pos = m_ptrListCol.GetHeadPosition();pos!=NULL;)
  241. {
  242. stColor *pColor = (stColor*)m_ptrListCol.GetNext(pos);
  243. if (pColor->nCol==col)
  244. {
  245. flag = 1;
  246. color = pColor->rgb;
  247. break;
  248. }
  249. }
  250. //LeaveCriticalSection( &m_SECTION );
  251. if (1==flag)
  252. {
  253. return true;
  254. }
  255. return false;
  256. }
  257. bool CListCtrlCl::FindItemColor(int col,int row,COLORREF &color) //查找颜色
  258. {
  259. //EnterCriticalSection( &m_SECTION );
  260. int flag = 0;
  261. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  262. {
  263. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  264. if (pColor->nCol==col&&pColor->nRow==row)
  265. {
  266. flag = 1;
  267. color = pColor->rgb;
  268. break;
  269. }
  270. }
  271. //LeaveCriticalSection( &m_SECTION );
  272. if (1==flag)
  273. {
  274. return true;
  275. }
  276. return false;
  277. }
  278. void CListCtrlCl::SetColColor(int col,COLORREF color) //设置列颜色
  279. {
  280. stColor *pColor = new stColor;
  281. pColor->nCol = col;
  282. pColor->rgb = color;
  283. m_ptrListCol.AddTail(pColor);
  284. }
  285. void CListCtrlCl::SetItemColor(int col,int row,COLORREF color) //设置格子颜色
  286. {
  287. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  288. {
  289. POSITION pos1 = pos;
  290. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  291. if (pColor->nCol==col&&pColor->nRow==row)
  292. {
  293. delete pColor;
  294. pColor = NULL;
  295. m_ptrListItem.RemoveAt( pos1 );
  296. break;
  297. }
  298. }
  299. stColor *pColor = new stColor;
  300. pColor->nCol = col;
  301. pColor->nRow = row;
  302. pColor->rgb = color;
  303. m_ptrListItem.AddTail(pColor);
  304. }
  305. void CListCtrlCl::SetRowHeigt(int nHeight) //高置行高
  306. {
  307. m_nRowHeight = nHeight;
  308. CRect rcWin;
  309. GetWindowRect(&rcWin);
  310. WINDOWPOS wp;
  311. wp.hwnd = m_hWnd;
  312. wp.cx = rcWin.Width();
  313. wp.cy = rcWin.Height();
  314. wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
  315. SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
  316. }
  317. void CListCtrlCl::SetHeaderFontHW(int nHeight,int nWith) //设置头部字体宽和高
  318. {
  319. m_Header.m_fontHeight = nHeight;
  320. m_Header.m_fontWith = nWith;
  321. }
  322. void CListCtrlCl::SetHeaderTextColor(COLORREF color) //设置头部字体颜色
  323. {
  324. m_Header.m_color = color;
  325. }
  326. BOOL CListCtrlCl::SetTextColor(COLORREF cr) //设置字体颜色
  327. {
  328. m_color = cr;
  329. return TRUE;
  330. }
  331. void CListCtrlCl::SetFontHW(int nHeight,int nWith) //设置字体高和宽
  332. {
  333. m_fontHeight = nHeight;
  334. m_fontWith = nWith;
  335. }
  336. void CListCtrlCl::SetColTextColor(int col,COLORREF color)
  337. {
  338. stColor *pColor = new stColor;
  339. pColor->nCol = col;
  340. pColor->rgb = color;
  341. m_colTextColor.AddTail(pColor);
  342. }
  343. bool CListCtrlCl::FindColTextColor(int col,COLORREF &color)
  344. {
  345. //EnterCriticalSection( &m_SECTION );
  346. int flag = 0;
  347. for (POSITION pos = m_colTextColor.GetHeadPosition();pos!=NULL;)
  348. {
  349. stColor *pColor = (stColor*)m_colTextColor.GetNext(pos);
  350. if (pColor->nCol==col)
  351. {
  352. flag = 1;
  353. color = pColor->rgb;
  354. break;
  355. }
  356. }
  357. //LeaveCriticalSection( &m_SECTION );
  358. if (1==flag)
  359. {
  360. return true;
  361. }
  362. return false;
  363. }
  364. bool CListCtrlCl::FindItemTextColor(int col,int row,COLORREF &color)
  365. {
  366. //EnterCriticalSection( &m_SECTION );
  367. int flag = 0;
  368. for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
  369. {
  370. stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
  371. if (pColor->nCol==col&&pColor->nRow==row)
  372. {
  373. flag = 1;
  374. color = pColor->rgb;
  375. break;
  376. }
  377. }
  378. //LeaveCriticalSection( &m_SECTION );
  379. if (1==flag)
  380. {
  381. return true;
  382. }
  383. return false;
  384. }
  385. void CListCtrlCl::SetItemTextColor(int col,int row,COLORREF color)
  386. {
  387. stColor *pColor = new stColor;
  388. pColor->nCol = col;
  389. pColor->nRow = row;
  390. pColor->rgb = color;
  391. m_ItemTextColor.AddTail(pColor);
  392. }
  393. void CListCtrlCl::OnLvnDeleteallitems(NMHDR *pNMHDR, LRESULT *pResult)
  394. {
  395. LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
  396. // TODO: 在此添加控件通知处理程序代码
  397. //EnterCriticalSection( &m_SECTION );
  398. for (POSITION pos = m_ptrListCol.GetHeadPosition();pos!=NULL;)
  399. {
  400. stColor *pColor = (stColor*)m_ptrListCol.GetNext(pos);
  401. delete pColor;
  402. pColor = NULL;
  403. }
  404. m_ptrListCol.RemoveAll();
  405. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  406. {
  407. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  408. delete pColor;
  409. pColor = NULL;
  410. }
  411. m_ptrListItem.RemoveAll();
  412. for (POSITION pos = m_colTextColor.GetHeadPosition();pos!=NULL;)
  413. {
  414. stColor *pColor = (stColor*)m_colTextColor.GetNext(pos);
  415. delete pColor;
  416. pColor = NULL;
  417. }
  418. m_colTextColor.RemoveAll();
  419. for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
  420. {
  421. stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
  422. delete pColor;
  423. pColor = NULL;
  424. }
  425. m_ItemTextColor.RemoveAll();
  426. //LeaveCriticalSection( &m_SECTION );
  427. *pResult = 0;
  428. }
  429. void CListCtrlCl::Edit()
  430. {
  431. EndEdit();
  432. CRect rect;
  433. if(GetSubItemRect(m_nRow,m_nCol,LVIR_LABEL,rect)==FALSE)
  434. return;
  435. int sty=WS_CHILD|WS_CLIPSIBLINGS|WS_EX_TOOLWINDOW|WS_BORDER;
  436. //int sty=WS_CHILD|WS_EX_TOOLWINDOW; //设置编辑框样式
  437. //设置编辑框样式
  438. if(m_edit.Create(sty,rect,this,IDC_EDITB)==FALSE)
  439. return;
  440. CString txt=GetItemText(m_nRow,m_nCol);
  441. m_edit.SetWindowText(txt);//设置编辑框的内容
  442. m_edit.SetFocus();
  443. m_edit.SetSel(0,-1);
  444. m_edit.ShowWindow(SW_SHOW);//显示编辑框
  445. Sleep(100);
  446. }
  447. void CListCtrlCl::EndEdit()
  448. {
  449. if( m_edit )//if(m_nRowOld!=-1&&m_nColOld!=-1)//判断是否为初始时
  450. {
  451. CString str;
  452. m_edit.GetWindowText(str);
  453. SetItemText(m_nRowOld,m_nColOld,str);//设置为编辑后的文件内容
  454. m_edit.DestroyWindow();
  455. }
  456. }
  457. void CListCtrlCl::Btn()
  458. {
  459. EndBtn();
  460. CRect rect;
  461. if(GetSubItemRect(m_nRow,m_nCol,LVIR_LABEL,rect)==FALSE)
  462. return;
  463. int sty=WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON;
  464. //int sty=WS_CHILD|WS_EX_TOOLWINDOW; //设置编辑框样式
  465. //设置编辑框样式
  466. rect.left = rect.right-20;
  467. CString txt=GetItemText(m_nRow,m_nCol);
  468. if(m_Btn.Create("...",sty,rect,this,IDC_BTN)==FALSE)
  469. return;
  470. m_Btn.ShowWindow(SW_SHOW);//显示编辑框
  471. //Sleep(100);
  472. }
  473. void CListCtrlCl::EndBtn()
  474. {
  475. if( m_Btn )
  476. m_Btn.DestroyWindow();
  477. }
  478. void CListCtrlCl::Comb()
  479. {
  480. EndComb();
  481. CRect rect;
  482. if(GetSubItemRect(m_nRow,m_nCol,LVIR_LABEL,rect)==FALSE)
  483. return;
  484. int sty=WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST;
  485. //int sty=WS_CHILD|WS_EX_TOOLWINDOW; //设置编辑框样式
  486. //设置编辑框样式
  487. //rect.left = rect.right-20;
  488. if(m_Comb.Create(sty,rect,this,IDC_COMB)==FALSE)
  489. return;
  490. m_Comb.SetWindowPos(NULL, rect.left, rect.top, rect.Width(), 500, SWP_NOZORDER);
  491. m_Comb.ShowWindow(SW_SHOW);//显示编辑框
  492. CString txt=GetItemText(m_nRow,m_nCol);
  493. int nSetCur=0;
  494. CString str;
  495. for( int i=0;i<m_saCombData[m_nCol].GetCount();i++ )
  496. {
  497. str = m_saCombData[m_nCol].GetAt( i );
  498. m_Comb.InsertString( i,str );
  499. if( txt==str )
  500. nSetCur=i;
  501. }
  502. m_Comb.SetCurSel(nSetCur);
  503. //Sleep(100);
  504. }
  505. void CListCtrlCl::EndComb()
  506. {
  507. if( m_Comb )
  508. {
  509. CString str;
  510. m_Comb.GetLBText( m_Comb.GetCurSel(),str );
  511. SetItemText(m_nRowOld,m_nColOld,str);
  512. m_Comb.DestroyWindow();
  513. }
  514. }
  515. void CListCtrlCl::EndAll()
  516. {
  517. EndBtn();
  518. EndEdit();
  519. EndComb();
  520. }
  521. void CListCtrlCl::SetItemType( int iCol,int iType )
  522. {
  523. m_nItemType[iCol] = iType;
  524. }
  525. void CListCtrlCl::SetRange( int iRowMin,int iRowMax,int iColMin,int iColMax )
  526. {
  527. m_nRowMin = iRowMin;
  528. m_nRowMax = iRowMax;
  529. m_nColMin = iColMin;
  530. m_nColMax = iColMax;
  531. }
  532. void CListCtrlCl::OnLButtonDown(UINT nFlags, CPoint point)
  533. {
  534. LVHITTESTINFO testinfo;
  535. testinfo.pt.x=point.x;
  536. testinfo.pt.y=point.y;
  537. testinfo.flags=LVHT_ONITEMLABEL;//强调点击必是标题
  538. if(SubItemHitTest(&testinfo)<0)
  539. return;
  540. m_nRow=testinfo.iItem;//得到行号
  541. m_nCol=testinfo.iSubItem;//得到列号
  542. if( m_nRow<m_nRowMin || m_nRow>m_nRowMax || m_nCol<m_nColMin || m_nCol>m_nColMax )
  543. return;
  544. if(m_nRow==m_nRowOld&&m_nCol==m_nColOld)//判断是否是前一点击的行列
  545. return;
  546. else
  547. {
  548. EndAll();
  549. switch( m_nItemType[m_nCol] )
  550. {
  551. case 1:
  552. Edit();
  553. break;
  554. case 2:
  555. Btn();
  556. break;
  557. case 3:
  558. Comb();
  559. break;
  560. }
  561. m_nRowOld=m_nRow;
  562. m_nColOld=m_nCol;
  563. }
  564. CListCtrl::OnLButtonDown(nFlags, point);
  565. }
  566. BOOL CListCtrlCl::OnCommand(WPARAM wParam, LPARAM lParam)
  567. {
  568. switch( HIWORD(wParam) )
  569. {
  570. case BN_CLICKED:
  571. {
  572. //test only!!
  573. //sprintf( ss,"%d",LOWORD(wParam) );
  574. //MessageBox(ss);
  575. //根据不同的 ID 做不同的处理...
  576. switch( LOWORD(wParam) )
  577. {
  578. case IDC_BTN:
  579. ::SendMessage( this->GetParent()->GetSafeHwnd(),WM_MY_BTN,0,0 );
  580. break;
  581. }
  582. }
  583. break;
  584. }
  585. return CListCtrl::OnCommand(wParam, lParam);
  586. }
  587. void CListCtrlCl::OnKillFocus(CWnd* pNewWnd)
  588. {
  589. CListCtrl::OnKillFocus(pNewWnd);
  590. // TODO: 在此处添加消息处理程序代码
  591. //EndAll();
  592. }
  593. void CListCtrlCl::OnLvnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult)
  594. {
  595. LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
  596. // TODO: 在此添加控件通知处理程序代码
  597. //Item颜色
  598. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  599. {
  600. POSITION pos1 = pos;
  601. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  602. if( pColor->nRow==pNMLV->iItem )
  603. {
  604. delete pColor;
  605. pColor = NULL;
  606. m_ptrListItem.RemoveAt( pos1 );
  607. }
  608. }
  609. for (POSITION pos = m_ptrListItem.GetHeadPosition();pos!=NULL;)
  610. {
  611. POSITION pos1 = pos;
  612. stColor *pColor = (stColor*)m_ptrListItem.GetNext(pos);
  613. if( pColor->nRow>pNMLV->iItem )
  614. {
  615. pColor->nRow--;
  616. }
  617. }
  618. //Item文本颜色
  619. for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
  620. {
  621. POSITION pos1 = pos;
  622. stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
  623. if( pColor->nRow==pNMLV->iItem )
  624. {
  625. delete pColor;
  626. pColor = NULL;
  627. m_ItemTextColor.RemoveAt( pos1 );
  628. }
  629. }
  630. for (POSITION pos = m_ItemTextColor.GetHeadPosition();pos!=NULL;)
  631. {
  632. POSITION pos1 = pos;
  633. stColor *pColor = (stColor*)m_ItemTextColor.GetNext(pos);
  634. if( pColor->nRow>pNMLV->iItem )
  635. {
  636. pColor->nRow--;
  637. }
  638. }
  639. *pResult = 0;
  640. }