ProcessPaste.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "ProcessPaste.h"
  4. #ifdef _DEBUG
  5. #undef THIS_FILE
  6. static char THIS_FILE[]=__FILE__;
  7. #define new DEBUG_NEW
  8. #endif
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CProcessPaste::CProcessPaste()
  13. {
  14. }
  15. CProcessPaste::~CProcessPaste()
  16. {
  17. }
  18. BOOL CProcessPaste::LoadDataAndPaste(long lID, HWND hWnd)
  19. {
  20. COleDataSource *pData = new COleDataSource;
  21. if(LoadData(lID, pData))
  22. {
  23. MarkDataAsPasted(lID);
  24. //Set this becase we just change the clipboard data so we will get a
  25. //clipboard change message
  26. //If this is set we don't handle that message
  27. theApp.m_bHandleClipboardDataChange = false;
  28. // pData->FlushClipboard();
  29. pData->SetClipboard();
  30. SendPaste(hWnd);
  31. //Set this back to handling messages
  32. theApp.m_bHandleClipboardDataChange = true;
  33. return TRUE;
  34. }
  35. return FALSE;
  36. }
  37. BOOL CProcessPaste::LoadDataAndDrag(long lID)
  38. {
  39. COleDataSource *pData = new COleDataSource;
  40. if(LoadData(lID, pData))
  41. {
  42. if(pData->DoDragDrop(DROPEFFECT_COPY) != DROPEFFECT_NONE)
  43. {
  44. MarkDataAsPasted(lID);
  45. return TRUE;
  46. }
  47. }
  48. return FALSE;
  49. }
  50. BOOL CProcessPaste::MarkDataAsPasted(long lID)
  51. {
  52. try
  53. {
  54. //Update the time it was copied so that it appears at the top of the
  55. //past list items are sorted by this time
  56. CMainTable ctMain;
  57. ctMain.Open("SELECT * FROM Main WHERE lID = %d", lID);
  58. ctMain.Edit();
  59. CTime now = CTime::GetCurrentTime();
  60. ctMain.m_lDate = (long)now.GetTime();
  61. ctMain.Update();
  62. ctMain.Close();
  63. CGetSetOptions::SetTripPasteCount(-1);
  64. CGetSetOptions::SetTotalPasteCount(-1);
  65. return TRUE;
  66. }
  67. catch(CDaoException *e)
  68. {
  69. ASSERT(FALSE);
  70. e->Delete();
  71. }
  72. return FALSE;
  73. }
  74. BOOL CProcessPaste::LoadData(long lID, COleDataSource *pData)
  75. {
  76. if(pData)
  77. {
  78. int nCounter = 0;
  79. try
  80. {
  81. CDataTable recset;
  82. //Open the data table for all that have the parent id
  83. CString csSQL, csFormatText;
  84. csSQL.Format("SELECT * FROM Data WHERE lParentID = %d", lID);
  85. recset.Open(AFX_DAO_USE_DEFAULT_TYPE, csSQL);
  86. //Go throught each item in the db putting it on the clipboard
  87. while(!recset.IsEOF())
  88. {
  89. csFormatText = recset.m_strClipBoardFormat;
  90. if(recset.LoadData(pData, GetFormatID(csFormatText)))
  91. nCounter++;
  92. recset.MoveNext();
  93. }
  94. recset.Close();
  95. if(nCounter)
  96. return TRUE;
  97. }
  98. catch(CDaoException* e)
  99. {
  100. ASSERT(FALSE);
  101. e->Delete();
  102. }
  103. }
  104. return FALSE;
  105. }
  106. void CProcessPaste::SendPaste(HWND hWnd)
  107. {
  108. if(hWnd)
  109. {
  110. //Set a Control key down then a 'V' down then the ups
  111. //To simulate a paste
  112. ::SetForegroundWindow(hWnd);
  113. ::SetFocus(hWnd);
  114. keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
  115. keybd_event('V', 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
  116. keybd_event('V', 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  117. keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  118. }
  119. else
  120. ASSERT(FALSE);
  121. }