DittoChaiScript.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "stdafx.h"
  2. #include "DittoChaiScript.h"
  3. #include "Shared\TextConvert.h"
  4. #include "Md5.h"
  5. #include "Misc.h"
  6. CDittoChaiScript::CDittoChaiScript(IClip *pClip, std::string activeApp)
  7. {
  8. m_pClip = pClip;
  9. m_activeApp = activeApp;
  10. }
  11. CDittoChaiScript::~CDittoChaiScript()
  12. {
  13. }
  14. std::string CDittoChaiScript::GetAsciiString()
  15. {
  16. std::string s = "";
  17. if (m_pClip)
  18. {
  19. IClipFormat *pFormat = m_pClip->Clips()->FindFormatEx(CF_TEXT);
  20. if (pFormat)
  21. {
  22. char *stringData = (char *)GlobalLock(pFormat->Data());
  23. if (stringData != NULL)
  24. {
  25. s = stringData;
  26. GlobalUnlock(pFormat->Data());
  27. }
  28. }
  29. }
  30. return s;
  31. }
  32. void CDittoChaiScript::SetAsciiString(std::string stringVal)
  33. {
  34. if (m_pClip)
  35. {
  36. m_pClip->Clips()->DeleteAll();
  37. HGLOBAL hGlobal = ::NewGlobalP((LPVOID)stringVal.c_str(), stringVal.size()+1);
  38. ASSERT(hGlobal);
  39. m_pClip->Clips()->AddNew(CF_TEXT, hGlobal);
  40. }
  41. }
  42. std::string CDittoChaiScript::GetClipMD5(std::string clipboardFormat)
  43. {
  44. CMd5 md5;
  45. md5.MD5Init();
  46. std::string md5String;
  47. if (m_pClip)
  48. {
  49. int formatId = GetFormatID(CTextConvert::MultiByteToUnicodeString(clipboardFormat.c_str()));
  50. IClipFormat *pFormat = m_pClip->Clips()->FindFormatEx(formatId);
  51. if (pFormat)
  52. {
  53. SIZE_T size = ::GlobalSize(pFormat->Data());
  54. void* pv = GlobalLock(pFormat->Data());
  55. if (pv != NULL)
  56. {
  57. md5.MD5Update((unsigned char*)pv, (unsigned int)size);
  58. GlobalUnlock(pFormat->Data());
  59. md5String = md5.MD5FinalToString();
  60. }
  61. }
  62. }
  63. return md5String;
  64. }
  65. SIZE_T CDittoChaiScript::GetClipSize(std::string clipboardFormat)
  66. {
  67. SIZE_T size = 0;
  68. if (m_pClip)
  69. {
  70. int formatId = GetFormatID(CTextConvert::MultiByteToUnicodeString(clipboardFormat.c_str()));
  71. IClipFormat *pFormat = m_pClip->Clips()->FindFormatEx(formatId);
  72. if (pFormat)
  73. {
  74. size = ::GlobalSize(pFormat->Data());
  75. }
  76. }
  77. return size;
  78. }