Leaked source code of windows server 2003
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.

262 lines
6.3 KiB

  1. #ifndef __PROGRESS_H_
  2. #define __PROGRESS_H_
  3. #include <wiadevdp.h>
  4. #include <validate.h>
  5. #define MEMORY_BLOCK_FACTOR 2
  6. #define TITLE_FROMDEVICE 101
  7. #define TITLE_PROCESSINGDATA 102
  8. #define TITLE_TRANSFERTOCLIENT 103
  9. //
  10. // Progress dialog class definition (uses common WIA UI)
  11. //
  12. class CProgressDlg {
  13. public:
  14. CProgressDlg()
  15. {
  16. m_bCancelled = FALSE;
  17. m_pWiaProgressDialog = NULL;
  18. m_iLow = 0;
  19. m_iHigh = 100;
  20. }
  21. ~CProgressDlg()
  22. {
  23. if (m_pWiaProgressDialog) {
  24. m_pWiaProgressDialog->Destroy();
  25. m_pWiaProgressDialog->Release();
  26. m_pWiaProgressDialog = NULL;
  27. }
  28. }
  29. BOOL Initialize(HINSTANCE hI, DWORD dwI)
  30. {
  31. return TRUE;
  32. }
  33. BOOL DoModeless(HWND hwndOwner, LPARAM lp)
  34. {
  35. //
  36. // Create standard WIA progress, allowing cancel
  37. //
  38. if(m_pWiaProgressDialog){
  39. // dialog has already been created
  40. return TRUE;
  41. }
  42. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaProgressDialog, (void**)&m_pWiaProgressDialog );
  43. if (SUCCEEDED(hr) && m_pWiaProgressDialog) {
  44. hr = m_pWiaProgressDialog->Create( hwndOwner, WIA_PROGRESSDLG_NO_ANIM );
  45. if (SUCCEEDED(hr)) {
  46. m_pWiaProgressDialog->SetTitle( L"" );
  47. m_pWiaProgressDialog->SetMessage( L"" );
  48. m_pWiaProgressDialog->SetPercentComplete(0);
  49. m_pWiaProgressDialog->Show();
  50. } else {
  51. m_pWiaProgressDialog->Release();
  52. m_pWiaProgressDialog = NULL;
  53. }
  54. }
  55. return(NULL != m_pWiaProgressDialog);
  56. }
  57. void SetRange(int Low, int High)
  58. {
  59. m_iLow = Low;
  60. m_iHigh = High;
  61. }
  62. void SetPos(int NewPos)
  63. {
  64. int delta = (m_iHigh - m_iLow) ;
  65. int percent = 0;
  66. if (NewPos < m_iLow ) {
  67. percent = 0;
  68. } else if ( (delta == 0) || (NewPos > m_iHigh) ) {
  69. percent = 100;
  70. } else {
  71. percent = 100 * ( NewPos - m_iLow) / delta;
  72. }
  73. ASSERT(m_pWiaProgressDialog != NULL);
  74. if (m_pWiaProgressDialog && FAILED(m_pWiaProgressDialog->SetPercentComplete(percent))) {
  75. }
  76. }
  77. BOOL CheckCancelled()
  78. {
  79. ASSERT(m_pWiaProgressDialog != NULL);
  80. m_bCancelled = FALSE;
  81. if (m_pWiaProgressDialog && FAILED(m_pWiaProgressDialog->Cancelled(&m_bCancelled))) {
  82. }
  83. return m_bCancelled;
  84. }
  85. void SetTitle(LPTSTR pszTitle)
  86. {
  87. ASSERT(m_pWiaProgressDialog != NULL);
  88. #ifndef UNICODE
  89. WCHAR wszTitle[MAX_PATH];
  90. MultiByteToWideChar(CP_ACP, 0, pszTitle, -1,
  91. wszTitle, sizeof(wszTitle) / sizeof(WCHAR)
  92. );
  93. if (m_pWiaProgressDialog && FAILED(m_pWiaProgressDialog->SetTitle(wszTitle))) {
  94. // What do we do if SetTitle fails?
  95. }
  96. #else
  97. if (m_pWiaProgressDialog && FAILED(m_pWiaProgressDialog->SetTitle(pszTitle))) {
  98. // What do we do if SetTitle fails?
  99. }
  100. #endif
  101. }
  102. private:
  103. BOOL m_bCancelled;
  104. IWiaProgressDialog *m_pWiaProgressDialog;
  105. int m_iLow;
  106. int m_iHigh;
  107. };
  108. //
  109. // WIA data callback class definition
  110. //
  111. class CWiaDataCallback : public IWiaDataCallback {
  112. public:
  113. CWiaDataCallback()
  114. {
  115. m_Ref = 1;
  116. m_hrLast = S_OK;
  117. //
  118. // image data
  119. //
  120. m_hImage = NULL;
  121. m_pImage = NULL;
  122. m_ImageSize = 0;
  123. m_bBitmapData = FALSE;
  124. m_lImageHeight = 0;
  125. m_lImageWidth = 0;
  126. m_MemBlockSize = 0;
  127. m_SizeTransferred = 0;
  128. //
  129. // progress dialog
  130. //
  131. m_hwndOwner = NULL;
  132. m_pProgDlg = NULL;
  133. m_pszXferFromDevice = NULL;
  134. m_pszProcessingData = NULL;
  135. m_pszXferToClient = NULL;
  136. m_bSetTitle = FALSE;
  137. m_lLastTextUpdate = 0;
  138. m_lCurrentTextUpdate = 0;
  139. }
  140. ~CWiaDataCallback()
  141. {
  142. //
  143. // free image data memory members
  144. //
  145. if (m_pImage){
  146. GlobalUnlock(m_hImage);
  147. m_pImage = NULL;
  148. }
  149. if (m_hImage){
  150. GlobalFree(m_hImage);
  151. m_hImage = NULL;
  152. }
  153. //
  154. // free progress dialog members
  155. //
  156. if (m_pProgDlg){
  157. delete m_pProgDlg;
  158. m_pProgDlg = NULL;
  159. }
  160. if (m_pszXferFromDevice){
  161. delete [] m_pszXferFromDevice;
  162. m_pszXferFromDevice = NULL;
  163. }
  164. if (m_pszProcessingData){
  165. delete [] m_pszProcessingData;
  166. m_pszProcessingData = NULL;
  167. }
  168. if (m_pszXferToClient){
  169. delete [] m_pszXferToClient;
  170. m_pszXferToClient = NULL;
  171. }
  172. }
  173. HRESULT Initialize(HWND hwndOwner, BOOL bShowProgress);
  174. STDMETHODIMP_(ULONG) AddRef();
  175. STDMETHODIMP_(ULONG) Release();
  176. STDMETHODIMP QueryInterface(REFIID iid, void **ppv);
  177. STDMETHODIMP BandedDataCallback(LONG lMessage, LONG lStatus,LONG lPercentComplete,LONG lOffset, LONG Length,
  178. LONG lReserved, LONG lResLength,BYTE *pData);
  179. HRESULT GetImage(HGLOBAL *phImage, ULONG *pImageSize);
  180. LONG CalculateWidthBytes(LONG lWidthPixels, LONG lbpp);
  181. LONG GetImageHeight(){return m_lImageHeight;}
  182. LONG GetImageWidth(){return m_lImageWidth;}
  183. HRESULT GetLastResult() {
  184. return m_hrLast;
  185. }
  186. private:
  187. ULONG m_Ref;
  188. HRESULT m_hrLast;
  189. //
  190. // image data
  191. //
  192. HGLOBAL m_hImage;
  193. BYTE *m_pImage;
  194. ULONG m_ImageSize;
  195. BOOL m_bBitmapData;
  196. LONG m_lImageHeight;
  197. LONG m_lImageWidth;
  198. LONG m_MemBlockSize;
  199. ULONG m_SizeTransferred;
  200. //
  201. // progress dialog
  202. //
  203. HWND m_hwndOwner;
  204. CProgressDlg *m_pProgDlg;
  205. TCHAR *m_pszXferFromDevice;
  206. TCHAR *m_pszProcessingData;
  207. TCHAR *m_pszXferToClient;
  208. BOOL m_bSetTitle;
  209. LONG m_lLastTextUpdate;
  210. LONG m_lCurrentTextUpdate;
  211. };
  212. #endif //__PROGRESS_H_