CF_TextAggregator.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "stdafx.h"
  2. #include ".\cf_textaggregator.h"
  3. #include "Misc.h"
  4. CCF_TextAggregator::CCF_TextAggregator(CStringA csSepator) :
  5. m_csSeparator(csSepator)
  6. {
  7. }
  8. CCF_TextAggregator::~CCF_TextAggregator(void)
  9. {
  10. }
  11. bool CCF_TextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
  12. {
  13. if (cfType == CF_HDROP)
  14. {
  15. CStringA hDropFiles = _T("");
  16. HDROP drop = (HDROP)GlobalLock((HDROP)lpData);
  17. int nNumFiles = DragQueryFileA(drop, -1, NULL, 0);
  18. CHAR file[MAX_PATH];
  19. for (int nFile = 0; nFile < nNumFiles; nFile++)
  20. {
  21. if (DragQueryFileA(drop, nFile, file, sizeof(file)) > 0)
  22. {
  23. hDropFiles += file;
  24. hDropFiles += "\r\n";
  25. }
  26. }
  27. if (hDropFiles != _T(""))
  28. {
  29. m_csNewText += hDropFiles;
  30. if (nPos != nCount - 1)
  31. {
  32. m_csNewText += m_csSeparator;
  33. }
  34. return true;
  35. }
  36. return false;
  37. }
  38. LPCSTR pText = (LPCSTR)lpData;
  39. if(pText == NULL)
  40. {
  41. return false;
  42. }
  43. //Ensure it's null terminated
  44. if(pText[nDataSize-1] != '\0')
  45. {
  46. int len = 0;
  47. for(len = 0; len < nDataSize && pText[len] != '\0'; len++ )
  48. {
  49. }
  50. // if it is not null terminated, skip this item
  51. if(len >= nDataSize)
  52. return false;
  53. }
  54. m_csNewText += pText;
  55. if(nPos != nCount-1)
  56. {
  57. m_csNewText += m_csSeparator;
  58. }
  59. return true;
  60. }
  61. HGLOBAL CCF_TextAggregator::GetHGlobal()
  62. {
  63. long lLen = m_csNewText.GetLength();
  64. HGLOBAL hGlobal = NewGlobalP(m_csNewText.GetBuffer(lLen), lLen+sizeof(char));
  65. m_csNewText.ReleaseBuffer();
  66. return hGlobal;
  67. }