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.

119 lines
5.0 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include <initguid.h>
  4. #include "pviewids.h"
  5. #include "wiatextc.h"
  6. #include "wiascand.h"
  7. #include "pshelper.h"
  8. #include "devprop.h"
  9. HRESULT WINAPI ScannerDeviceDialog( PDEVICEDIALOGDATA pDialogDeviceData )
  10. {
  11. HRESULT hr = E_FAIL;
  12. if (pDialogDeviceData && pDialogDeviceData->cbSize == sizeof(DEVICEDIALOGDATA))
  13. {
  14. InitCommonControls();
  15. RegisterWiaPreviewClasses( g_hInstance );
  16. CWiaTextControl::RegisterClass( g_hInstance );
  17. WIA_ERROR((TEXT("GetWindowThreadProcessId( pDialogDeviceData->hwndParent ): %08X, GetCurrentThreadId(): %08X"), GetWindowThreadProcessId( pDialogDeviceData->hwndParent, NULL ), GetCurrentThreadId() ));
  18. LONG nProps = ScannerProperties::GetDeviceProps( pDialogDeviceData->pIWiaItemRoot );
  19. int nDialogId = 0;
  20. //
  21. // Determine which dialog resource to use, based on which properties the scanner has, as follows:
  22. //
  23. // HasFlatBed HasDocumentFeeder SupportsPreview SupportsPageSize
  24. // 1 1 1 1 IDD_SCAN_ADF
  25. // 1 0 1 0 IDD_SCAN_NORMAL
  26. // 0 1 1 1 IDD_SCAN_ADF
  27. // 0 1 0 0 IDD_SCAN_NO_PREVIEW
  28. //
  29. // otheriwse return E_NOTIMPL
  30. //
  31. const int nMaxControllingProps = 4;
  32. static struct
  33. {
  34. LONG ControllingProps[nMaxControllingProps];
  35. int pszDialogTemplate;
  36. }
  37. s_DialogResourceData[] =
  38. {
  39. { ScannerProperties::HasFlatBed, ScannerProperties::HasDocumentFeeder, ScannerProperties::SupportsPreview, ScannerProperties::SupportsPageSize, NULL },
  40. { ScannerProperties::HasFlatBed, ScannerProperties::HasDocumentFeeder, ScannerProperties::SupportsPreview, ScannerProperties::SupportsPageSize, IDD_SCAN_ADF },
  41. { ScannerProperties::HasFlatBed, 0, ScannerProperties::SupportsPreview, 0, IDD_SCAN },
  42. { 0, ScannerProperties::HasDocumentFeeder, ScannerProperties::SupportsPreview, ScannerProperties::SupportsPageSize, IDD_SCAN_ADF },
  43. { 0, ScannerProperties::HasDocumentFeeder, 0, 0, IDD_SCAN_NO_PREVIEW },
  44. { 0, ScannerProperties::HasDocumentFeeder, 0, ScannerProperties::SupportsPageSize, IDD_SCAN_ADF },
  45. { ScannerProperties::HasFlatBed, ScannerProperties::HasDocumentFeeder, 0, ScannerProperties::SupportsPageSize, IDD_SCAN_ADF }
  46. };
  47. //
  48. // Find the set of flags that match this device. If they match, use this resource.
  49. // Loop through each resource description.
  50. //
  51. for (int nCurrentResourceFlags=1;nCurrentResourceFlags<ARRAYSIZE(s_DialogResourceData) && !nDialogId;nCurrentResourceFlags++)
  52. {
  53. //
  54. // Loop through each controlling property
  55. //
  56. for (int nControllingProp=0;nControllingProp<nMaxControllingProps;nControllingProp++)
  57. {
  58. //
  59. // If this property DOESN'T match, break out prematurely
  60. //
  61. if ((nProps & s_DialogResourceData[0].ControllingProps[nControllingProp]) != s_DialogResourceData[nCurrentResourceFlags].ControllingProps[nControllingProp])
  62. {
  63. break;
  64. }
  65. }
  66. //
  67. // If the current controlling property is equal to the maximum controlling property,
  68. // we had matches all the way through, so use this resource
  69. //
  70. if (nControllingProp == nMaxControllingProps)
  71. {
  72. nDialogId = s_DialogResourceData[nCurrentResourceFlags].pszDialogTemplate;
  73. }
  74. }
  75. //
  76. // If we didn't find a match, return E_NOTIMPL
  77. //
  78. if (!nDialogId)
  79. {
  80. return E_NOTIMPL;
  81. }
  82. //
  83. // Open the dialog
  84. //
  85. INT_PTR nResult = DialogBoxParam( g_hInstance, MAKEINTRESOURCE(nDialogId), pDialogDeviceData->hwndParent, CScannerAcquireDialog::DialogProc, (LPARAM)pDialogDeviceData );
  86. if (-1 == nResult)
  87. {
  88. //
  89. // Some kind of system error occurred
  90. //
  91. hr = HRESULT_FROM_WIN32(GetLastError());
  92. //
  93. // Make sure we return some kind of error
  94. //
  95. if (hr == S_OK)
  96. {
  97. hr = E_FAIL;
  98. }
  99. }
  100. else
  101. {
  102. //
  103. // Just cast the return value to an HRESULT
  104. //
  105. hr = static_cast<HRESULT>(nResult);
  106. }
  107. }
  108. return hr;
  109. }