CF_UnicodeTextAggregator.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "stdafx.h"
  2. #include ".\cf_unicodetextaggregator.h"
  3. #include "Misc.h"
  4. CCF_UnicodeTextAggregator::CCF_UnicodeTextAggregator(CStringW csSeparator) :
  5. m_csSeparator(csSeparator)
  6. {
  7. }
  8. CCF_UnicodeTextAggregator::~CCF_UnicodeTextAggregator(void)
  9. {
  10. }
  11. bool CCF_UnicodeTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
  12. {
  13. if (cfType == CF_HDROP)
  14. {
  15. CString hDropFiles = _T("");
  16. HDROP drop = (HDROP)GlobalLock((HDROP)lpData);
  17. int nNumFiles = DragQueryFile(drop, -1, NULL, 0);
  18. TCHAR file[MAX_PATH];
  19. for (int nFile = 0; nFile < nNumFiles; nFile++)
  20. {
  21. if (DragQueryFile(drop, nFile, file, sizeof(file)) > 0)
  22. {
  23. hDropFiles += file;
  24. hDropFiles += _T("\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. LPCWSTR pText = (LPCWSTR)lpData;
  39. if(pText == NULL)
  40. {
  41. return false;
  42. }
  43. int stringLen = nDataSize/sizeof(wchar_t);
  44. //Ensure it's null terminated
  45. if(pText[stringLen-1] != '\0')
  46. {
  47. int len = 0;
  48. for(len = 0; len < stringLen && pText[len] != '\0'; len++ )
  49. {
  50. }
  51. // if it is not null terminated, skip this item
  52. if(len >= stringLen)
  53. return false;
  54. }
  55. m_csNewText += pText;
  56. if(nPos != nCount-1)
  57. {
  58. m_csNewText += m_csSeparator;
  59. }
  60. return true;
  61. }
  62. HGLOBAL CCF_UnicodeTextAggregator::GetHGlobal()
  63. {
  64. long lLen = m_csNewText.GetLength() * sizeof(wchar_t);
  65. HGLOBAL hGlobal = NewGlobalP(m_csNewText.GetBuffer(lLen), lLen+sizeof(wchar_t));
  66. m_csNewText.ReleaseBuffer();
  67. return hGlobal;
  68. }