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.

172 lines
4.4 KiB

  1. #ifndef __UTILS__H
  2. #define __UTILS__H
  3. #ifdef UNICODE
  4. #define LSTRNCPY(str1, str2, n) wcsncpy(str1, str2, n)
  5. #else
  6. #define LSTRNCPY(str1, str2, n) strncpy(str1, str2, n)
  7. #endif
  8. #define AToU(dst, cchDst, src) \
  9. MultiByteToWideChar(CP_ACP, 0, src, -1, dst, cchDst)
  10. #define UToA(dst, cchDst, src) \
  11. WideCharToMultiByte(CP_ACP, 0, src, -1, dst, cchDst, 0, 0)
  12. #ifdef UNICODE
  13. #define SToT AToU
  14. #define TToS UToA
  15. #define AToT AToU
  16. #define TToU(dst, cchDst, src) lstrcpyn(dst, src, cchDst)
  17. #else
  18. #define SToT UToA
  19. #define TToS AToU
  20. #define AToT(dst, cchDst, src) lstrcpyn(dst, src, cchDst)
  21. #define TToU AToU
  22. #endif
  23. //
  24. // WIA->TWAIN Capability Conversions
  25. //
  26. TW_UINT16 WIA_IPA_COMPRESSION_TO_ICAP_COMPRESSION(LONG lCompression);
  27. TW_UINT16 WIA_IPA_DATATYPE_TO_ICAP_PIXELTYPE(LONG lDataType);
  28. TW_UINT16 WIA_IPA_FORMAT_TO_ICAP_IMAGEFILEFORMAT(GUID guidFormat);
  29. //
  30. // TWAIN->WIA Property Conversions
  31. //
  32. LONG ICAP_COMPRESSION_TO_WIA_IPA_COMPRESSION(TW_UINT16 Compression);
  33. LONG ICAP_PIXELTYPE_TO_WIA_IPA_DATATYPE(TW_UINT16 PixelType);
  34. GUID ICAP_IMAGEFILEFORMAT_TO_WIA_IPA_FORMAT(TW_UINT16 ImageFileFormat);
  35. //
  36. // BITMAP / DIB data helper function definitions
  37. //
  38. #define BMPFILE_HEADER_MARKER ((WORD) ('M' << 8) | 'B')
  39. TW_UINT16 WriteDIBToFile(LPSTR szFileName, HGLOBAL hDIB);
  40. int GetDIBBitsOffset(BITMAPINFO *pbmi);
  41. UINT GetDIBLineSize(UINT Width, UINT BitCount);
  42. BOOL FlipDIB(HGLOBAL hDIB, BOOL bUpsideDown = FALSE);
  43. UINT GetLineSize(PMEMORY_TRANSFER_INFO pInfo);
  44. //
  45. // string resource loader helper function definition
  46. //
  47. LPTSTR LoadResourceString(int StringId);
  48. //
  49. // TWAIN condition code (TW_STATUS) conversion helper function
  50. //
  51. TW_UINT16 TWCC_FROM_HRESULT(HRESULT hr);
  52. //
  53. // data source manager class definition
  54. //
  55. class CDSM
  56. {
  57. public:
  58. CDSM();
  59. ~CDSM();
  60. BOOL Notify(TW_IDENTITY *pSrc, TW_IDENTITY *pDst,
  61. TW_UINT32 twDG, TW_UINT16 twDAT, TW_UINT16 Msg,
  62. TW_MEMREF pData);
  63. private:
  64. HINSTANCE m_hDSM;
  65. DSMENTRYPROC m_DSMEntry;
  66. };
  67. //
  68. // dialog class definition
  69. //
  70. class CDialog
  71. {
  72. public:
  73. CDialog()
  74. {
  75. m_TemplateId = -1;
  76. m_hInst = NULL;
  77. m_hDlg = NULL;
  78. }
  79. void Initialize(HINSTANCE hInst, int TemplateId)
  80. {
  81. m_hInst = hInst;
  82. m_TemplateId = TemplateId;
  83. }
  84. virtual ~CDialog()
  85. {}
  86. static INT_PTR CALLBACK DialogWndProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  87. INT_PTR DoModal(HWND hwndOwner, LPARAM lParam)
  88. {
  89. if (m_hInst && -1 != m_TemplateId)
  90. return DialogBoxParam(m_hInst, MAKEINTRESOURCE(m_TemplateId),
  91. hwndOwner, DialogWndProc, lParam);
  92. else
  93. return -1;
  94. }
  95. BOOL DoModeless(HWND hwndOwner, LPARAM lParam)
  96. {
  97. if (m_hInst && -1 != m_TemplateId)
  98. m_hDlg = CreateDialogParam(m_hInst, MAKEINTRESOURCE(m_TemplateId),
  99. hwndOwner, DialogWndProc, lParam);
  100. return NULL != m_hDlg;
  101. }
  102. virtual BOOL OnInitDialog()
  103. {
  104. return TRUE;
  105. }
  106. virtual void OnCommand(WPARAM wParam, LPARAM lParam)
  107. {}
  108. virtual BOOL OnHelp(LPHELPINFO pHelpInfo)
  109. {
  110. return FALSE;
  111. }
  112. virtual BOOL OnNotify(LPNMHDR pnmh)
  113. {
  114. SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, FALSE);
  115. return TRUE;
  116. }
  117. virtual BOOL OnContextMenu(HWND hWnd, WORD xPos, WORD yPos)
  118. {
  119. return FALSE;
  120. }
  121. virtual BOOL OnMiscMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
  122. {
  123. return FALSE;
  124. }
  125. LRESULT SendControlMsg( int ControlId, UINT Msg, WPARAM wParam = 0, LPARAM lParam = 0)
  126. {
  127. return SendDlgItemMessage(m_hDlg, ControlId, Msg, wParam, lParam);
  128. }
  129. HWND GetControl(int idControl)
  130. {
  131. return GetDlgItem(m_hDlg, idControl);
  132. }
  133. BOOL SetTitle(LPCTSTR Title)
  134. {
  135. if (m_hDlg)
  136. return ::SetWindowText(m_hDlg, Title);
  137. return FALSE;
  138. }
  139. operator HWND()
  140. {
  141. return m_hDlg;
  142. }
  143. HWND m_hDlg;
  144. protected:
  145. HINSTANCE m_hInst;
  146. int m_TemplateId;
  147. };
  148. #endif // __UTILS_H_