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.

73 lines
2.2 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "itranhlp.h"
  4. #include "wiadevdp.h"
  5. HRESULT GetImageDialog( IWiaDevMgr *pIWiaDevMgr, HWND hwndParent, LONG lDeviceType, LONG lFlags, LONG lIntent, IWiaItem *pSuppliedItemRoot, BSTR bstrFilename, GUID *pguidFormat )
  6. {
  7. HRESULT hr;
  8. CComPtr<IWiaItem> pRootItem;
  9. // Put up a wait cursor
  10. CWaitCursor wc;
  11. if (!pIWiaDevMgr || !pguidFormat || !bstrFilename)
  12. {
  13. WIA_ERROR((TEXT("GetImageDlg: Invalid pIWiaDevMgr, pguidFormat or bstrFilename")));
  14. return(E_POINTER);
  15. }
  16. // If a root item wasn't passed, select the device.
  17. if (pSuppliedItemRoot == NULL)
  18. {
  19. hr = pIWiaDevMgr->SelectDeviceDlg( hwndParent, lDeviceType, lFlags, NULL, &pRootItem );
  20. if (FAILED(hr))
  21. {
  22. WIA_ERROR((TEXT("GetImageDlg, SelectDeviceDlg failed")));
  23. return(hr);
  24. }
  25. if (hr != S_OK)
  26. {
  27. WIA_ERROR((TEXT("GetImageDlg, DeviceDlg cancelled")));
  28. return(hr);
  29. }
  30. }
  31. else
  32. {
  33. pRootItem = pSuppliedItemRoot;
  34. }
  35. // Put up the device UI.
  36. LONG nItemCount;
  37. IWiaItem **ppIWiaItem;
  38. //
  39. // Specify WIA_DEVICE_DIALOG_SINGLE_IMAGE to prevent multiple selection
  40. //
  41. hr = pRootItem->DeviceDlg( hwndParent, lFlags|WIA_DEVICE_DIALOG_SINGLE_IMAGE, lIntent, &nItemCount, &ppIWiaItem );
  42. if (SUCCEEDED(hr) && hr == S_OK)
  43. {
  44. if (ppIWiaItem && nItemCount)
  45. {
  46. CComPtr<IWiaTransferHelper> pWiaTransferHelper;
  47. hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaTransferHelper, (void**)&pWiaTransferHelper );
  48. if (SUCCEEDED(hr))
  49. {
  50. hr = pWiaTransferHelper->TransferItemFile( ppIWiaItem[0], hwndParent, 0, *pguidFormat, bstrFilename, NULL, TYMED_FILE );
  51. }
  52. }
  53. // Release the items and free the array memory
  54. for (int i=0; ppIWiaItem && i<nItemCount; i++)
  55. {
  56. if (ppIWiaItem[i])
  57. {
  58. ppIWiaItem[i]->Release();
  59. }
  60. }
  61. if (ppIWiaItem)
  62. CoTaskMemFree(ppIWiaItem);
  63. }
  64. return(hr);
  65. }