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.

171 lines
4.1 KiB

  1. // CWIA.H
  2. #ifndef _CWIA_H
  3. #define _CWIA_H
  4. #include "wia.h"
  5. #include "datatypes.h"
  6. #include "sti.h"
  7. #define MIN_PROPID 2
  8. //
  9. // helper MACROS
  10. //
  11. #define RECTWIDTH(lpRect) ((lpRect)->right - (lpRect)->left)
  12. #define RECTHEIGHT(lpRect) ((lpRect)->bottom - (lpRect)->top)
  13. typedef BOOL (*FPPROGRESS)(LPTSTR lpszText, LONG lPercentComplete);
  14. typedef struct _DATA_ACQUIRE_INFO {
  15. DWORD dwCookie;
  16. FPPROGRESS pProgressFunc;
  17. BOOL bPreview;
  18. BOOL bTransferToFile;
  19. BOOL bTransferToClipboard;
  20. CHAR szFileName[256];
  21. HBITMAP hBitmap;
  22. HWND hWnd;
  23. HGLOBAL hClipboardData;
  24. HGLOBAL hBitmapData;
  25. } DATA_ACQUIRE_INFO;
  26. //
  27. // global helpers, for all to use
  28. //
  29. HRESULT WriteInterfaceToGlobalInterfaceTable(DWORD *pdwCookie, IWiaItem *pIWiaItem);
  30. HRESULT ReadInterfaceFromGlobalInterfaceTable(DWORD dwCookie, IWiaItem **ppIWiaItem);
  31. class CWIA {
  32. public:
  33. CWIA(DATA_ACQUIRE_INFO* pDataAcquireInfo = NULL, IWiaItem *pRootItem = NULL);
  34. ~CWIA();
  35. VOID CleanUp();
  36. //
  37. // operations
  38. //
  39. HRESULT GetLastWIAError(TCHAR *pszErrorText = NULL);
  40. HRESULT ReadRangeLong(IWiaItem *pIWiaItem, PROPID propid, ULONG ulFlag, LONG *plVal);
  41. HRESULT ReadLong(IWiaItem *pIWiaItem, PROPID propid, LONG *plVal);
  42. HRESULT ReadStr(IWiaItem *pIWiaItem, PROPID propid, BSTR *pbstr);
  43. HRESULT ReadGuid(IWiaItem *pIWiaItem, PROPID propid, GUID *pguidVal);
  44. HRESULT WriteLong(IWiaItem *pIWiaItem, PROPID propid, LONG lVal);
  45. HRESULT WriteGuid(IWiaItem *pIWiaItem, PROPID propid, GUID guidVal);
  46. HRESULT DoBandedTransfer(DATA_ACQUIRE_INFO* pDataAcquireInfo);
  47. HRESULT DoFileTransfer(DATA_ACQUIRE_INFO* pDataAcquireInfo);
  48. BOOL IsAcquireComplete();
  49. HRESULT EnumerateSupportedFormats(IWiaItem *pIWiaItem, WIA_FORMAT_INFO **ppSupportedFormats, ULONG *pulCount);
  50. //
  51. // Root Item operations
  52. //
  53. VOID SetRootItem(IWiaItem *pRootItem);
  54. IWiaItem *GetRootItem();
  55. LONG GetRootItemType(IWiaItem *pRootItem = NULL);
  56. //
  57. // standard item operations
  58. //
  59. BOOL SetFirstChild();
  60. IWiaItem *GetFirstChild();
  61. private:
  62. //
  63. // helpers
  64. //
  65. VOID SaveErrorText(TCHAR *pszText);
  66. //
  67. // Read/Write LONG properties
  68. //
  69. HRESULT WritePropLong(PROPID propid, IWiaPropertyStorage *pIWiaPropStg, LONG lVal);
  70. HRESULT ReadPropLong(PROPID propid, IWiaPropertyStorage *pIWiaPropStg, LONG *plval);
  71. //
  72. // Read/Write GUID properties
  73. //
  74. HRESULT WritePropGUID(PROPID propid, IWiaPropertyStorage *pIWiaPropStg, GUID guidVal);
  75. HRESULT ReadPropGUID(PROPID propid, IWiaPropertyStorage *pIWiaPropStg, GUID *pguidVal);
  76. //
  77. // Read/Write BSTR properties
  78. //
  79. HRESULT ReadPropStr(PROPID propid,IWiaPropertyStorage *pIWiaPropStg,BSTR *pbstr);
  80. HRESULT WritePropStr(PROPID propid, IWiaPropertyStorage *pIWiaPropStg, BSTR bstr);
  81. protected:
  82. IWiaItem *m_pIWiaRootItem;
  83. IWiaItem *m_pIWiaFirstChildItem;
  84. BOOL m_bFinishedAcquire;
  85. TCHAR m_szErrorText[MAX_PATH];
  86. HRESULT m_hrLastError;
  87. };
  88. //
  89. // IWiaDataCallback Data callback transfer
  90. //
  91. class CWiaDataCallback : public IWiaDataCallback
  92. {
  93. private:
  94. ULONG m_cRef; // Object reference count.
  95. LONG m_MemBlockSize;
  96. LONG m_BytesTransfered;
  97. GUID m_cFormat;
  98. FPPROGRESS m_pProgressFunc;
  99. LONG m_lPageCount;
  100. BOOL m_bCanceled;
  101. DATA_ACQUIRE_INFO* m_pDataAcquireInfo;
  102. BOOL m_bBitmapCreated;
  103. public:
  104. CWiaDataCallback();
  105. ~CWiaDataCallback();
  106. HRESULT _stdcall QueryInterface(const IID&,void**);
  107. ULONG _stdcall AddRef();
  108. ULONG _stdcall Release();
  109. //
  110. // public members
  111. //
  112. HRESULT _stdcall Initialize(DATA_ACQUIRE_INFO* pDataAcquireInfo = NULL);
  113. HRESULT _stdcall BandedDataCallback(LONG lMessage,
  114. LONG lStatus,
  115. LONG lPercentComplete,
  116. LONG lOffset,
  117. LONG lLength,
  118. LONG lReserved,
  119. LONG lResLength,
  120. BYTE* pbBuffer);
  121. private:
  122. //
  123. // helpers
  124. //
  125. VOID AddDataToHBITMAP(HWND hWnd, HGLOBAL hBitmapData, HBITMAP *phBitmap, LONG lOffset);
  126. VOID CreateHBITMAP(HWND hWnd, HGLOBAL hBitmapData, HBITMAP *phBitmap, LONG lOffset);
  127. void ScreenRectToClientRect(HWND hWnd,LPRECT pRect);
  128. };
  129. #endif