Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.2 KiB

  1. // WiaDataCallback.cpp: implementation of the CWiaDataCallback class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "wiatest.h"
  6. #include "WiaDataCallback.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CWiaDataCallback::CWiaDataCallback()
  16. {
  17. m_cRef = 0;
  18. m_pBuffer = NULL;
  19. m_BytesTransferred = 0;
  20. m_pAcquireDlg = NULL;
  21. m_lBufferSize = 65535; // default
  22. m_bBitmapData = FALSE;
  23. m_bNewPageArrived = TRUE;
  24. // initialize progress dialog
  25. m_pAcquireDlg = new CWiaAcquireDlg();
  26. if(m_pAcquireDlg){
  27. m_pAcquireDlg->Create(IDD_DATA_ACQUISITION_DIALOG,NULL);
  28. m_pAcquireDlg->ShowWindow(TRUE);
  29. }
  30. }
  31. CWiaDataCallback::~CWiaDataCallback()
  32. {
  33. if (m_pBuffer != NULL){
  34. LocalFree(m_pBuffer);
  35. m_pBuffer = NULL;
  36. }
  37. if(m_pAcquireDlg){
  38. m_pAcquireDlg->DestroyWindow();
  39. delete m_pAcquireDlg;
  40. m_pAcquireDlg = NULL;
  41. }
  42. }
  43. HRESULT _stdcall CWiaDataCallback::QueryInterface(const IID& iid, void** ppv)
  44. {
  45. *ppv = NULL;
  46. if (iid == IID_IUnknown || iid == IID_IWiaDataCallback)
  47. *ppv = (IWiaDataCallback*) this;
  48. else
  49. return E_NOINTERFACE;
  50. AddRef();
  51. return S_OK;
  52. }
  53. ULONG _stdcall CWiaDataCallback::AddRef()
  54. {
  55. InterlockedIncrement((long*) &m_cRef);
  56. return m_cRef;
  57. }
  58. ULONG _stdcall CWiaDataCallback::Release()
  59. {
  60. ULONG ulRefCount = m_cRef - 1;
  61. if (InterlockedDecrement((long*) &m_cRef) == 0)
  62. {
  63. delete this;
  64. return 0;
  65. }
  66. return ulRefCount;
  67. }
  68. HRESULT _stdcall CWiaDataCallback::BandedDataCallback(LONG lMessage, LONG lStatus,
  69. LONG lPercentComplete, LONG lOffset,
  70. LONG lLength, LONG lReserved, LONG lResLength, BYTE* pbBuffer)
  71. {
  72. // check for cancel button presses
  73. if(m_pAcquireDlg->CheckCancelButton()){
  74. return S_FALSE;
  75. }
  76. PWIA_DATA_CALLBACK_HEADER pHeader = NULL;
  77. switch (lMessage) {
  78. case IT_MSG_DATA_HEADER:
  79. pHeader = (PWIA_DATA_CALLBACK_HEADER)pbBuffer;
  80. if(pHeader->guidFormatID == WiaImgFmt_MEMORYBMP){
  81. m_bBitmapData = TRUE;
  82. }
  83. m_MemBlockSize = pHeader->lBufferSize;
  84. if(m_MemBlockSize <= 0)
  85. m_MemBlockSize = m_lBufferSize;
  86. m_pBuffer = (PBYTE)LocalAlloc(LPTR,m_MemBlockSize);
  87. m_BytesTransferred = 0;
  88. UpdateAcqusitionDialog(TEXT("IT_MSG_DATA_HEADER"),lPercentComplete);
  89. break;
  90. case IT_MSG_DATA:
  91. if(m_bNewPageArrived){
  92. m_BytesTransferred = 0;
  93. m_bNewPageArrived = FALSE;
  94. }
  95. if (m_pBuffer != NULL) {
  96. m_BytesTransferred += lLength;
  97. if(m_BytesTransferred >= m_MemBlockSize){
  98. m_MemBlockSize += (lLength * MEMORY_BLOCK_FACTOR);
  99. m_pBuffer = (PBYTE)LocalReAlloc(m_pBuffer,m_MemBlockSize,LMEM_MOVEABLE);
  100. }
  101. memcpy(m_pBuffer + lOffset, pbBuffer, lLength);
  102. }
  103. UpdateAcqusitionDialog(TEXT("IT_MSG_DATA"),lPercentComplete);
  104. break;
  105. case IT_MSG_STATUS:
  106. if (lStatus & IT_STATUS_TRANSFER_FROM_DEVICE){
  107. UpdateAcqusitionDialog(TEXT("IT_MSG_STATUS\n(IT_STATUS_TRANSFER_FROM_DEVICE)"),lPercentComplete);
  108. } else if (lStatus & IT_STATUS_PROCESSING_DATA){
  109. UpdateAcqusitionDialog(TEXT("IT_MSG_STATUS\n(IT_STATUS_PROCESSING_DATA)"),lPercentComplete);
  110. } else if (lStatus & IT_STATUS_TRANSFER_TO_CLIENT) {
  111. UpdateAcqusitionDialog(TEXT("IT_MSG_STATUS\n(IT_STATUS_TRANSFER_TO_CLIENT)"),lPercentComplete);
  112. }
  113. break;
  114. case IT_MSG_NEW_PAGE:
  115. UpdateAcqusitionDialog(TEXT("IT_MSG_NEWPAGE"),0);
  116. pHeader = (PWIA_DATA_CALLBACK_HEADER)pbBuffer;
  117. m_lPageCount = pHeader->lPageCount;
  118. m_bNewPageArrived = TRUE;
  119. break;
  120. case IT_MSG_FILE_PREVIEW_DATA:
  121. UpdateAcqusitionDialog(TEXT("IT_MSG_FILE_PREVIEW_DATA"),-1);
  122. break;
  123. case IT_MSG_FILE_PREVIEW_DATA_HEADER:
  124. UpdateAcqusitionDialog(TEXT("IT_MSG_FILE_PREVIEW_DATA_HEADER"),-1);
  125. break;
  126. case IT_MSG_TERMINATION:
  127. UpdateAcqusitionDialog(TEXT("IT_MSG_TERMINATION"),-1);
  128. break;
  129. default:
  130. break;
  131. }
  132. return S_OK;
  133. }
  134. void CWiaDataCallback::UpdateAcqusitionDialog(TCHAR *szMessage, LONG lPercentComplete)
  135. {
  136. m_pAcquireDlg->SetCallbackMessage(szMessage);
  137. if(lPercentComplete > -1){
  138. m_pAcquireDlg->SetPercentComplete(lPercentComplete);
  139. m_pAcquireDlg->m_AcquireProgressCtrl.SetPos(lPercentComplete);
  140. }
  141. }
  142. void CWiaDataCallback::SetBufferSizeRequest(LONG lBufferSize)
  143. {
  144. m_lBufferSize = lBufferSize;
  145. }
  146. BYTE* CWiaDataCallback::GetCallbackMemoryPtr(LONG *plDataSize)
  147. {
  148. *plDataSize = m_BytesTransferred;
  149. return m_pBuffer;
  150. }
  151. BOOL CWiaDataCallback::IsBITMAPDATA()
  152. {
  153. return m_bBitmapData;
  154. }