FileListBox.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // FileListBox.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "BurnCD.h"
  5. #include "FileListBox.h"
  6. #include "FileObject.h"
  7. #include "DirObject.h"
  8. // CFileListBox
  9. IMPLEMENT_DYNAMIC(CFileListBox, CListBox)
  10. CFileListBox::CFileListBox()
  11. {
  12. }
  13. CFileListBox::~CFileListBox()
  14. {
  15. }
  16. BEGIN_MESSAGE_MAP(CFileListBox, CListBox)
  17. ON_WM_MEASUREITEM()
  18. END_MESSAGE_MAP()
  19. // CFileListBox message handlers
  20. void CFileListBox::PreSubclassWindow()
  21. {
  22. //ModifyStyle(0,LBS_OWNERDRAWFIXED);
  23. CListBox::PreSubclassWindow();
  24. }
  25. BOOL CFileListBox::PreCreateWindow(CREATESTRUCT& cs)
  26. {
  27. cs.style |= LBS_OWNERDRAWFIXED;
  28. return CListBox::PreCreateWindow(cs);
  29. }
  30. void CFileListBox::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMIS)
  31. {
  32. lpMIS->itemHeight = 24;
  33. CListBox::OnMeasureItem(nIDCtl, lpMIS);
  34. }
  35. void CFileListBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  36. {
  37. if (lpDIS->itemID == -1)
  38. return;
  39. CString strFile;
  40. CObject* pObject = (CObject*)GetItemData(lpDIS->itemID);
  41. ASSERT(pObject != NULL);
  42. if (pObject == NULL)
  43. return;
  44. if (!pObject->IsKindOf(RUNTIME_CLASS(CBaseObject)))
  45. return;
  46. CBaseObject* pBaseObject = (CBaseObject*)pObject;
  47. strFile = pBaseObject->GetPath();
  48. SHFILEINFO shFileInfo = {0};
  49. ::SHGetFileInfo(strFile, 0, &shFileInfo, sizeof(SHFILEINFO),
  50. SHGFI_DISPLAYNAME|SHGFI_ICON|SHGFI_SMALLICON);
  51. CRect rect(lpDIS->rcItem);
  52. HBRUSH hBrush;
  53. COLORREF clrText;
  54. if (lpDIS->itemState & ODS_SELECTED)
  55. {
  56. hBrush = GetSysColorBrush(COLOR_HIGHLIGHT);
  57. clrText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  58. }
  59. else
  60. {
  61. hBrush = GetSysColorBrush(COLOR_WINDOW);
  62. clrText = GetSysColor(COLOR_WINDOWTEXT);
  63. }
  64. ::FillRect(lpDIS->hDC, &lpDIS->rcItem, hBrush);
  65. if (lpDIS->itemState & ODS_FOCUS)
  66. ::DrawFocusRect(lpDIS->hDC, &rect);
  67. DrawIconEx(lpDIS->hDC, rect.left + 4, rect.top+4, shFileInfo.hIcon,
  68. 16, 16, 0, NULL, DI_NORMAL);
  69. COLORREF oldColor = ::SetTextColor(lpDIS->hDC, clrText);
  70. int nOldMode = ::SetBkMode(lpDIS->hDC, TRANSPARENT);
  71. rect.left += 24;
  72. DrawText(lpDIS->hDC, shFileInfo.szDisplayName,
  73. (int)_tcslen(shFileInfo.szDisplayName), &rect,
  74. DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
  75. ::SetBkMode(lpDIS->hDC, nOldMode);
  76. ::SetTextColor(lpDIS->hDC, oldColor);
  77. }
  78. void CFileListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
  79. {
  80. lpMIS->itemHeight = 24;
  81. }