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.

2279 lines
84 KiB

  1. // wiatestView.cpp : implementation of the CWiatestView class
  2. //
  3. #include "stdafx.h"
  4. #include "wiatest.h"
  5. #include "wiatestDoc.h"
  6. #include "wiatestView.h"
  7. #include "wiaeditpropdlg.h"
  8. #include "wiacapdlg.h"
  9. #include "wiaacquiredlg.h"
  10. #include "wiadatacallback.h"
  11. #include "wiadocacqsettings.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CWiatestView
  19. IMPLEMENT_DYNCREATE(CWiatestView, CFormView)
  20. BEGIN_MESSAGE_MAP(CWiatestView, CFormView)
  21. //{{AFX_MSG_MAP(CWiatestView)
  22. ON_NOTIFY(TVN_SELCHANGED, IDC_ITEM_TREECTRL, OnSelchangedItemTreectrl)
  23. ON_WM_SIZE()
  24. ON_NOTIFY(NM_DBLCLK, IDC_ITEMPROPERTIES_LISTCTRL, OnDblclkItempropertiesListctrl)
  25. ON_COMMAND(IDM_ACQUIREIMAGE, OnAcquireimage)
  26. ON_COMMAND(IDM_LOAD_WIAPROPERTYSTREAM, OnLoadWiapropertystream)
  27. ON_COMMAND(IDM_SAVE_WIAPROPERTYSTREAM, OnSaveWiapropertystream)
  28. ON_NOTIFY(NM_RCLICK, IDC_ITEMPROPERTIES_LISTCTRL, OnRclickItempropertiesListctrl)
  29. ON_COMMAND(ID_PROPERTYEDITPOPUPMENU_EDITPROPERTYVALUE, OnPropertyeditpopupmenuEditpropertyvalue)
  30. ON_COMMAND(IDM_VIEW_CAPABILITIES, OnViewCapabilities)
  31. ON_NOTIFY(NM_RCLICK, IDC_ITEM_TREECTRL, OnRclickItemTreectrl)
  32. ON_COMMAND(IDM_DELETE_ITEM, OnDeleteItem)
  33. ON_COMMAND(IDM_ACQUIREIMAGE_COMMONUI, OnAcquireimageCommonui)
  34. ON_COMMAND(IDM_EDIT_DEBUGOUT, OnEditDebugout)
  35. ON_UPDATE_COMMAND_UI(IDM_EDIT_DEBUGOUT, OnUpdateEditDebugout)
  36. ON_WM_SHOWWINDOW()
  37. ON_COMMAND(IDM_DOCUMENT_ACQUISITION_SETTINGS, OnDocumentAcquisitionSettings)
  38. ON_UPDATE_COMMAND_UI(IDM_DOCUMENT_ACQUISITION_SETTINGS, OnUpdateDocumentAcquisitionSettings)
  39. ON_LBN_SELCHANGE(IDC_SUPPORTED_TYMED_AND_FORMAT_LISTBOX, OnSelchangeSupportedTymedAndFormatListbox)
  40. ON_BN_CLICKED(IDC_THUMBNAIL_PREVIEW, OnThumbnailPreview)
  41. //}}AFX_MSG_MAP
  42. // Standard printing commands
  43. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  44. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  45. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CWiatestView construction/destruction
  49. CWiatestView::CWiatestView()
  50. : CFormView(CWiatestView::IDD)
  51. {
  52. m_bOutputToDebuggerON = FALSE;
  53. m_hThumbNailBitmap = NULL;
  54. m_bHasDocumentFeeder = FALSE;
  55. //{{AFX_DATA_INIT(CWiatestView)
  56. // NOTE: the ClassWizard will add member initialization here
  57. //}}AFX_DATA_INIT
  58. // TODO: add construction code here
  59. }
  60. CWiatestView::~CWiatestView()
  61. {
  62. }
  63. void CWiatestView::DoDataExchange(CDataExchange* pDX)
  64. {
  65. CFormView::DoDataExchange(pDX);
  66. //{{AFX_DATA_MAP(CWiatestView)
  67. DDX_Control(pDX, IDC_SUPPORTED_TYMED_AND_FORMAT_LISTBOX, m_SupportedTymedAndFormatsListBox);
  68. DDX_Control(pDX, IDC_THUMBNAIL_PREVIEW, m_ThumbnailPreviewWindow);
  69. DDX_Control(pDX, IDC_ITEMPROPERTIES_LISTCTRL, m_ItemPropertiesListCtrl);
  70. DDX_Control(pDX, IDC_ITEM_TREECTRL, m_ItemTreeCtrl);
  71. //}}AFX_DATA_MAP
  72. }
  73. BOOL CWiatestView::PreCreateWindow(CREATESTRUCT& cs)
  74. {
  75. return CFormView::PreCreateWindow(cs);
  76. }
  77. void CWiatestView::OnInitialUpdate()
  78. {
  79. CFormView::OnInitialUpdate();
  80. GetParentFrame()->RecalcLayout();
  81. ResizeParentToFit(FALSE);
  82. // get associated document
  83. CWiatestDoc* pDocument = NULL;
  84. pDocument = (CWiatestDoc*)m_pDocument;
  85. if(pDocument){
  86. // initialize item tree control
  87. AddWiaItemsToTreeControl(TVI_ROOT, pDocument->m_pIRootItem);
  88. // initialize property list control
  89. m_ItemPropertiesListCtrl.SetupColumnHeaders();
  90. // initialize supported TYMED and formats list box
  91. AddSupportedTYMEDAndFormatsToListBox(pDocument->m_pIRootItem);
  92. // initialize device type specifics for UI
  93. AdjustViewForDeviceType();
  94. // register for events
  95. RegisterForEvents();
  96. // maximize window
  97. CWnd* Parent = GetParent();
  98. Parent->ShowWindow(SW_SHOWMAXIMIZED);
  99. }
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CWiatestView printing
  103. BOOL CWiatestView::OnPreparePrinting(CPrintInfo* pInfo)
  104. {
  105. // default preparation
  106. return DoPreparePrinting(pInfo);
  107. }
  108. void CWiatestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  109. {
  110. // TODO: add extra initialization before printing
  111. }
  112. void CWiatestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  113. {
  114. // TODO: add cleanup after printing
  115. }
  116. void CWiatestView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  117. {
  118. // TODO: add customized printing code here
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CWiatestView diagnostics
  122. #ifdef _DEBUG
  123. void CWiatestView::AssertValid() const
  124. {
  125. CFormView::AssertValid();
  126. }
  127. void CWiatestView::Dump(CDumpContext& dc) const
  128. {
  129. CFormView::Dump(dc);
  130. }
  131. CWiatestDoc* CWiatestView::GetDocument() // non-debug version is inline
  132. {
  133. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWiatestDoc)));
  134. return (CWiatestDoc*)m_pDocument;
  135. }
  136. #endif //_DEBUG
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CWiatestView message handlers
  139. void CWiatestView::AddWiaItemsToTreeControl(HTREEITEM hParent, IWiaItem *pIWiaItem)
  140. {
  141. if(hParent == TVI_ROOT){
  142. // delete any old items in tree
  143. m_ItemTreeCtrl.DeleteAllItems();
  144. }
  145. TV_INSERTSTRUCT tv;
  146. HRESULT hr = S_OK;
  147. IEnumWiaItem* pIEnumWiaItem = NULL;
  148. LONG lItemType = 0;
  149. HTREEITEM hNewParent = NULL;
  150. TCHAR szItemName[MAX_PATH];
  151. CWiahelper WIA;
  152. memset(szItemName,0,sizeof(szItemName));
  153. tv.hParent = hParent;
  154. tv.hInsertAfter = TVI_LAST;
  155. tv.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
  156. tv.item.hItem = NULL;
  157. tv.item.state = TVIS_EXPANDED;
  158. tv.item.stateMask = TVIS_STATEIMAGEMASK;
  159. tv.item.cchTextMax = 6;
  160. tv.item.cChildren = 0;
  161. tv.item.lParam = 0;
  162. // get item's full name
  163. WIA.SetIWiaItem(pIWiaItem);
  164. WIA.ReadPropertyString(WIA_IPA_FULL_ITEM_NAME,szItemName);
  165. tv.item.pszText = szItemName;
  166. // insert item into tree
  167. hNewParent = m_ItemTreeCtrl.InsertItem(&tv);
  168. // check item type to see if it is a parent
  169. hr = pIWiaItem->GetItemType(&lItemType);
  170. if(SUCCEEDED(hr)){
  171. if(lItemType & (WiaItemTypeFolder | WiaItemTypeHasAttachments)){
  172. // we have a potential parent
  173. hr = pIWiaItem->EnumChildItems(&pIEnumWiaItem);
  174. if(S_OK == hr){
  175. ULONG ulFetched = 0;
  176. IWiaItem *pFoundIWiaItem = NULL;
  177. // we have a parent with children
  178. hr = pIEnumWiaItem->Next(1,&pFoundIWiaItem,&ulFetched);
  179. while(S_OK == hr){
  180. // add item to tree
  181. AddWiaItemsToTreeControl(hNewParent,pFoundIWiaItem);
  182. // release enumerated item
  183. pFoundIWiaItem->Release();
  184. hr = pIEnumWiaItem->Next(1,&pFoundIWiaItem,&ulFetched);
  185. }
  186. }
  187. }
  188. }
  189. }
  190. void CWiatestView::OnSelchangedItemTreectrl(NMHDR* pNMHDR, LRESULT* pResult)
  191. {
  192. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  193. HTREEITEM hTreeItem = NULL;
  194. hTreeItem = m_ItemTreeCtrl.GetSelectedItem();
  195. if(hTreeItem){
  196. CString cszItemName = m_ItemTreeCtrl.GetItemText(hTreeItem);
  197. if(cszItemName.GetLength() > 0){
  198. CWiatestDoc* pDocument = NULL;
  199. pDocument = (CWiatestDoc*)m_pDocument;
  200. if(pDocument){
  201. BSTR bstrFullItemName = NULL;
  202. bstrFullItemName = cszItemName.AllocSysString();
  203. if(bstrFullItemName){
  204. HRESULT hr = S_OK;
  205. IWiaItem *pFoundIWiaItem = NULL;
  206. hr = pDocument->m_pIRootItem->FindItemByName(0,bstrFullItemName,&pFoundIWiaItem);
  207. if(SUCCEEDED(hr)){
  208. if(NULL != pFoundIWiaItem){
  209. hr = pDocument->SetCurrentIWiaItem(pFoundIWiaItem);
  210. if(SUCCEEDED(hr)){
  211. // update list control with properties of the selected (found) item
  212. AddWiaItemPropertiesToListControl(pDocument->m_pICurrentItem);
  213. // update valid TYMED/Formats listbox selections
  214. AddSupportedTYMEDAndFormatsToListBox(pDocument->m_pICurrentItem);
  215. // disable supported TYMED and format selection if the item selected
  216. // is a root item.
  217. if(pDocument->m_pICurrentItem == pDocument->m_pIRootItem){
  218. m_SupportedTymedAndFormatsListBox.SetCurSel(-1);
  219. m_SupportedTymedAndFormatsListBox.EnableWindow(FALSE);
  220. } else {
  221. m_SupportedTymedAndFormatsListBox.EnableWindow(TRUE);
  222. // set current selection for TYMED and format listbox
  223. SetCurrentSelectionForTYMEDAndFormat();
  224. }
  225. // display thumbnail if one exists
  226. DisplayThumbnail(pDocument->m_pICurrentItem);
  227. // release IWiaItem
  228. pFoundIWiaItem->Release();
  229. pFoundIWiaItem = NULL;
  230. }
  231. } else {
  232. ErrorMessageBox(IDS_WIATESTERROR_ITEMNOTFOUND,hr);
  233. }
  234. } else {
  235. ErrorMessageBox(IDS_WIATESTERROR_ITEMNOTFOUND,hr);
  236. }
  237. SysFreeString(bstrFullItemName);
  238. bstrFullItemName = NULL;
  239. }
  240. }
  241. }
  242. }
  243. *pResult = 0;
  244. }
  245. void CWiatestView::AddWiaItemPropertiesToListControl(IWiaItem *pIWiaItem)
  246. {
  247. // erase any old properties
  248. m_ItemPropertiesListCtrl.DeleteAllItems();
  249. // insert new properties
  250. HRESULT hr = S_OK;
  251. IWiaPropertyStorage *pIWiaPropStg = NULL;
  252. INT ItemNumber = 0;
  253. hr = pIWiaItem->QueryInterface(IID_IWiaPropertyStorage,(void **)&pIWiaPropStg);
  254. if(hr == S_OK) {
  255. IEnumSTATPROPSTG *pIPropEnum = NULL;
  256. hr = pIWiaPropStg->Enum(&pIPropEnum);
  257. if(hr == S_OK) {
  258. STATPROPSTG StatPropStg;
  259. memset(&StatPropStg,0,sizeof(StatPropStg));
  260. do {
  261. hr = pIPropEnum->Next(1,&StatPropStg,NULL);
  262. if (hr == S_OK) {
  263. if (StatPropStg.lpwstrName != NULL) {
  264. // read property value
  265. PROPSPEC PropSpec;
  266. PROPVARIANT PropVar;
  267. PropSpec.ulKind = PRSPEC_PROPID;
  268. PropSpec.propid = StatPropStg.propid;
  269. hr = pIWiaPropStg->ReadMultiple(1,&PropSpec,&PropVar);
  270. if (hr == S_OK) {
  271. TCHAR szPropName[MAX_PATH];
  272. memset(szPropName,0,sizeof(szPropName));
  273. TCHAR szValue[MAX_PATH];
  274. memset(szValue,0,sizeof(szValue));
  275. TCHAR szText[MAX_PATH];
  276. memset(szText,0,sizeof(szText));
  277. LV_ITEM lvitem;
  278. lvitem.mask = LVIF_TEXT | LVIF_PARAM;
  279. lvitem.iItem = ItemNumber;
  280. lvitem.iSubItem = 0;
  281. lvitem.pszText = szText;
  282. lvitem.iImage = NULL;
  283. lvitem.lParam = StatPropStg.propid;
  284. // Write property name to list control
  285. if (WideCharToMultiByte(CP_ACP, 0,StatPropStg.lpwstrName,-1,
  286. szPropName, MAX_PATH,NULL,NULL) > 0) {
  287. lstrcpy(szText,szPropName);
  288. // insert name into list control
  289. m_ItemPropertiesListCtrl.InsertItem(&lvitem);
  290. // move to next column for setting the value
  291. lvitem.mask = LVIF_TEXT;
  292. lvitem.iSubItem = 1;
  293. } else {
  294. lstrcpy(szPropName,TEXT("<MISSING NAME>"));
  295. }
  296. // Write property value to list control
  297. PROPVAR2TSTR(&PropVar,szText);
  298. m_ItemPropertiesListCtrl.SetItem(&lvitem);
  299. // display access flags and var type
  300. ULONG AccessFlags = 0;
  301. ULONG VarType = 0;
  302. PROPVARIANT AttrPropVar; // not used at this time
  303. hr = pIWiaPropStg->GetPropertyAttributes(1, &PropSpec,&AccessFlags,&AttrPropVar);
  304. if (hr != S_OK) {
  305. hr = S_OK; // do this to continue property traversal
  306. } else {
  307. // display access flags
  308. lvitem.mask = LVIF_TEXT;
  309. lvitem.iSubItem = 3;
  310. memset(lvitem.pszText,0,sizeof(szText));
  311. AccessFlags2TSTR(lvitem.pszText,AccessFlags);
  312. m_ItemPropertiesListCtrl.SetItem(&lvitem);
  313. }
  314. // display var type
  315. lvitem.mask = LVIF_TEXT;
  316. lvitem.iSubItem = 2;
  317. VT2TSTR(lvitem.pszText,PropVar.vt);
  318. m_ItemPropertiesListCtrl.SetItem(&lvitem);
  319. // increment Row counter
  320. ItemNumber++;
  321. }
  322. } else {
  323. }
  324. }
  325. // clean up property name
  326. CoTaskMemFree(StatPropStg.lpwstrName);
  327. } while (hr == S_OK);
  328. pIPropEnum->Release();
  329. } else {
  330. ErrorMessageBox(IDS_WIATESTERROR_ENUMERATE_PROPERTIES,hr);
  331. }
  332. pIWiaPropStg->Release();
  333. } else {
  334. ErrorMessageBox(IDS_WIATESTERROR_WIAPROPERTYSTORAGE,hr);
  335. }
  336. // auto resize columns
  337. for (int Col = 0; Col <4;Col++){
  338. m_ItemPropertiesListCtrl.SetColumnWidth(Col, LVSCW_AUTOSIZE);
  339. }
  340. }
  341. void CWiatestView::VT2TSTR(TCHAR *pszText,ULONG VarType)
  342. {
  343. if (pszText == NULL)
  344. return;
  345. switch (VarType) {
  346. case VT_EMPTY: // nothing
  347. lstrcpy(pszText,TEXT("VT_EMPTY"));
  348. break;
  349. case VT_NULL: // SQL style Null
  350. lstrcpy(pszText,TEXT("VT_NULL"));
  351. break;
  352. case VT_I2: // 2 byte signed int
  353. lstrcpy(pszText,TEXT("VT_I2"));
  354. break;
  355. case VT_I4: // 4 byte signed int
  356. lstrcpy(pszText,TEXT("VT_I4"));
  357. break;
  358. case VT_R4: // 4 byte real
  359. lstrcpy(pszText,TEXT("VT_R4"));
  360. break;
  361. case VT_R8: // 8 byte real
  362. lstrcpy(pszText,TEXT("VT_R8"));
  363. break;
  364. case VT_CY: // currency
  365. lstrcpy(pszText,TEXT("VT_CY"));
  366. break;
  367. case VT_DATE: // date
  368. lstrcpy(pszText,TEXT("VT_DATE"));
  369. break;
  370. case VT_BSTR: // OLE Automation string
  371. lstrcpy(pszText,TEXT("VT_BSTR"));
  372. break;
  373. case VT_DISPATCH: // IDispatch *
  374. lstrcpy(pszText,TEXT("VT_DISPATCH"));
  375. break;
  376. case VT_ERROR: // SCODE
  377. lstrcpy(pszText,TEXT("VT_ERROR"));
  378. break;
  379. case VT_BOOL: // True=-1, False=0
  380. lstrcpy(pszText,TEXT("VT_BOOL"));
  381. break;
  382. case VT_VARIANT: // VARIANT *
  383. lstrcpy(pszText,TEXT("VT_VARIANT"));
  384. break;
  385. case VT_UNKNOWN: // IUnknown *
  386. lstrcpy(pszText,TEXT("VT_UNKNOWN"));
  387. break;
  388. case VT_DECIMAL: // 16 byte fixed point
  389. lstrcpy(pszText,TEXT("VT_DECIMAL"));
  390. break;
  391. case VT_RECORD: // user defined type
  392. lstrcpy(pszText,TEXT("VT_RECORD"));
  393. break;
  394. case VT_I1: // signed char
  395. lstrcpy(pszText,TEXT("VT_I1"));
  396. break;
  397. case VT_UI1: // unsigned char
  398. lstrcpy(pszText,TEXT("VT_UI1"));
  399. break;
  400. case VT_UI2: // unsigned short
  401. lstrcpy(pszText,TEXT("VT_UI2"));
  402. break;
  403. case VT_UI4: // unsigned short
  404. lstrcpy(pszText,TEXT("VT_UI4"));
  405. break;
  406. case VT_I8: // signed 64-bit int
  407. lstrcpy(pszText,TEXT("VT_I8"));
  408. break;
  409. case VT_UI8: // unsigned 64-bit int
  410. lstrcpy(pszText,TEXT("VT_UI8"));
  411. break;
  412. case VT_INT: // signed machine int
  413. lstrcpy(pszText,TEXT("VT_INT"));
  414. break;
  415. case VT_UINT: // unsigned machine int
  416. lstrcpy(pszText,TEXT("VT_UINT"));
  417. break;
  418. case VT_VOID: // C style void
  419. lstrcpy(pszText,TEXT("VT_VOID"));
  420. break;
  421. case VT_HRESULT: // Standard return type
  422. lstrcpy(pszText,TEXT("VT_HRESULT"));
  423. break;
  424. case VT_PTR: // pointer type
  425. lstrcpy(pszText,TEXT("VT_PTR"));
  426. break;
  427. case VT_SAFEARRAY: // (use VT_ARRAY in VARIANT)
  428. lstrcpy(pszText,TEXT("VT_SAFEARRAY"));
  429. break;
  430. case VT_CARRAY: // C style array
  431. lstrcpy(pszText,TEXT("VT_CARRAY"));
  432. break;
  433. case VT_USERDEFINED: // user defined type
  434. lstrcpy(pszText,TEXT("VT_USERDEFINED"));
  435. break;
  436. case VT_LPSTR: // null terminated string
  437. lstrcpy(pszText,TEXT("VT_LPSTR"));
  438. break;
  439. case VT_LPWSTR: // wide null terminated string
  440. lstrcpy(pszText,TEXT("VT_LPWSTR"));
  441. break;
  442. case VT_FILETIME: // FILETIME
  443. lstrcpy(pszText,TEXT("VT_FILETIME"));
  444. break;
  445. case VT_BLOB: // Length prefixed bytes
  446. lstrcpy(pszText,TEXT("VT_BLOB"));
  447. break;
  448. case VT_STREAM: // Name of the stream follows
  449. lstrcpy(pszText,TEXT("VT_STREAM"));
  450. break;
  451. case VT_STORAGE: // Name of the storage follows
  452. lstrcpy(pszText,TEXT("VT_STORAGE"));
  453. break;
  454. case VT_STREAMED_OBJECT: // Stream contains an object
  455. lstrcpy(pszText,TEXT("VT_STREAMED_OBJECT"));
  456. break;
  457. case VT_STORED_OBJECT: // Storage contains an object
  458. lstrcpy(pszText,TEXT("VT_STORED_OBJECT"));
  459. break;
  460. case VT_VERSIONED_STREAM: // Stream with a GUID version
  461. lstrcpy(pszText,TEXT("VT_VERSIONED_STREAM"));
  462. break;
  463. case VT_BLOB_OBJECT: // Blob contains an object
  464. lstrcpy(pszText,TEXT("VT_BLOB_OBJECT"));
  465. break;
  466. case VT_CF: // Clipboard format
  467. lstrcpy(pszText,TEXT("VT_CF"));
  468. break;
  469. case VT_CLSID: // A Class ID
  470. lstrcpy(pszText,TEXT("VT_CLSID"));
  471. break;
  472. case VT_VECTOR: // simple counted array
  473. lstrcpy(pszText,TEXT("VT_VECTOR"));
  474. break;
  475. case VT_ARRAY: // SAFEARRAY*
  476. lstrcpy(pszText,TEXT("VT_ARRAY"));
  477. break;
  478. case VT_BYREF: // void* for local use
  479. lstrcpy(pszText,TEXT("VT_BYREF"));
  480. break;
  481. case VT_BSTR_BLOB: // Reserved for system use
  482. lstrcpy(pszText,TEXT("VT_BSTR_BLOB"));
  483. break;
  484. case VT_VECTOR|VT_I4:
  485. lstrcpy(pszText,TEXT("VT_VECTOR | VT_I4"));
  486. break;
  487. case VT_VECTOR | VT_UI1:
  488. lstrcpy(pszText,TEXT("VT_VECTOR | VT_UI1"));
  489. break;
  490. case VT_VECTOR | VT_UI2:
  491. lstrcpy(pszText,TEXT("VT_VECTOR | VT_UI2"));
  492. break;
  493. case VT_VECTOR | VT_UI4:
  494. lstrcpy(pszText,TEXT("VT_VECTOR | VT_UI4"));
  495. break;
  496. default: // unknown type detected!!
  497. lstrcpy(pszText,TEXT("VT_UNKNOWNTYPE"));
  498. break;
  499. }
  500. }
  501. void CWiatestView::AccessFlags2TSTR(TCHAR *pszText,ULONG AccessFlags)
  502. {
  503. if (pszText == NULL)
  504. return;
  505. if ((AccessFlags & WIA_PROP_READ) == WIA_PROP_READ){
  506. lstrcat(pszText,TEXT("WIA_PROP_READ | "));
  507. }
  508. if ((AccessFlags & WIA_PROP_WRITE) == WIA_PROP_WRITE){
  509. lstrcat(pszText,TEXT("WIA_PROP_WRITE | "));
  510. }
  511. if (lstrcmp(pszText,TEXT("WIA_PROP_READ | WIA_PROP_WRITE | ")) == 0){
  512. lstrcpy(pszText,TEXT("WIA_PROP_RW | "));
  513. }
  514. if ((AccessFlags & WIA_PROP_NONE) == WIA_PROP_NONE){
  515. lstrcat(pszText,TEXT("WIA_PROP_NONE | "));
  516. }
  517. if ((AccessFlags & WIA_PROP_RANGE) == WIA_PROP_RANGE){
  518. lstrcat(pszText,TEXT("WIA_PROP_RANGE | "));
  519. }
  520. if ((AccessFlags & WIA_PROP_LIST) == WIA_PROP_LIST){
  521. lstrcat(pszText,TEXT("WIA_PROP_LIST | "));
  522. }
  523. if ((AccessFlags & WIA_PROP_FLAG) == WIA_PROP_FLAG){
  524. lstrcat(pszText,TEXT("WIA_PROP_FLAG | "));
  525. }
  526. LONG lLen = 0;
  527. lLen = lstrlen(pszText);
  528. // check for unknown access flags
  529. if (lLen == 0){
  530. TSPRINTF(pszText,TEXT("WIA_PROP_UNKNOWN = %d "),AccessFlags);
  531. return;
  532. }
  533. pszText[lLen - (2 * sizeof(TCHAR))] = 0;
  534. }
  535. void CWiatestView::PROPVAR2TSTR(PROPVARIANT *pPropVar,TCHAR *szValue)
  536. {
  537. SYSTEMTIME *pSystemTime = NULL;
  538. switch (pPropVar->vt) {
  539. case VT_I1:
  540. TSPRINTF(szValue,TEXT("%d"),pPropVar->cVal);
  541. break;
  542. case VT_UI1:
  543. TSPRINTF(szValue,TEXT("%d"),pPropVar->bVal);
  544. break;
  545. case VT_I2:
  546. TSPRINTF(szValue,TEXT("%d"),pPropVar->iVal);
  547. break;
  548. case VT_UI2:
  549. TSPRINTF(szValue,TEXT("%d"),pPropVar->uiVal);
  550. break;
  551. case VT_UI4:
  552. TSPRINTF(szValue,TEXT("%d"),pPropVar->ulVal);
  553. break;
  554. case VT_UI8:
  555. TSPRINTF(szValue,TEXT("%d"),pPropVar->lVal);
  556. break;
  557. case VT_INT:
  558. TSPRINTF(szValue,TEXT("%d"),pPropVar->intVal);
  559. break;
  560. case VT_I4:
  561. TSPRINTF(szValue,TEXT("%d"),pPropVar->lVal);
  562. break;
  563. case VT_I8:
  564. TSPRINTF(szValue,TEXT("%d"),pPropVar->hVal);
  565. break;
  566. case VT_R4:
  567. TSPRINTF(szValue,TEXT("%2.5f"),pPropVar->fltVal);
  568. break;
  569. case VT_R8:
  570. TSPRINTF(szValue,TEXT("%2.5f"),pPropVar->dblVal);
  571. break;
  572. case VT_BSTR:
  573. #ifndef UNICODE
  574. WideCharToMultiByte(CP_ACP, 0,pPropVar->bstrVal, -1, szValue, MAX_PATH,NULL,NULL);
  575. #else
  576. TSPRINTF(szValue,TEXT("%ws"),pPropVar->bstrVal);
  577. #endif
  578. break;
  579. case VT_LPSTR:
  580. TSPRINTF(szValue,TEXT("%s"),pPropVar->pwszVal);
  581. break;
  582. case VT_LPWSTR:
  583. TSPRINTF(szValue,TEXT("%ws"),pPropVar->pwszVal);
  584. break;
  585. case VT_UINT:
  586. TSPRINTF(szValue,TEXT("%d"),pPropVar->uintVal);
  587. break;
  588. case VT_CLSID:
  589. {
  590. UCHAR *pwszUUID = NULL;
  591. UuidToString(pPropVar->puuid,&pwszUUID);
  592. if(NULL != pwszUUID){
  593. TSPRINTF(szValue,TEXT("%s"),pwszUUID);
  594. // free allocated string
  595. RpcStringFree(&pwszUUID);
  596. }
  597. }
  598. break;
  599. case VT_VECTOR | VT_UI2:
  600. pSystemTime = (SYSTEMTIME*)pPropVar->caui.pElems;
  601. if(NULL != pSystemTime){
  602. // ( YYYY:MM:W:DD:HH:MM:SS:ms )
  603. TSPRINTF(szValue,TEXT("%d:%d:%d:%d:%d:%d:%d:%d"),pSystemTime->wYear,
  604. pSystemTime->wMonth,
  605. pSystemTime->wDay,
  606. pSystemTime->wDayOfWeek,
  607. pSystemTime->wHour,
  608. pSystemTime->wMinute,
  609. pSystemTime->wSecond,
  610. pSystemTime->wMilliseconds);
  611. }
  612. break;
  613. default:
  614. TSPRINTF(szValue,TEXT("%d"),pPropVar->lVal);
  615. break;
  616. }
  617. }
  618. void CWiatestView::TSTR2PROPVAR(TCHAR *szValue, PROPVARIANT *pPropVar)
  619. {
  620. WCHAR wszbuffer[MAX_PATH];
  621. CHAR szbuffer[MAX_PATH];
  622. memset(wszbuffer,0,sizeof(wszbuffer));
  623. memset(szbuffer,0,sizeof(szbuffer));
  624. switch (pPropVar->vt) {
  625. case VT_I1:
  626. TSSCANF(szValue,TEXT("%li"),&pPropVar->cVal);
  627. break;
  628. case VT_I2:
  629. TSSCANF(szValue,TEXT("%li"),&pPropVar->bVal);
  630. break;
  631. case VT_I4:
  632. TSSCANF(szValue,TEXT("%li"),&pPropVar->lVal);
  633. break;
  634. case VT_I8:
  635. TSSCANF(szValue,TEXT("%li"),&pPropVar->hVal);
  636. break;
  637. case VT_UI1:
  638. TSSCANF(szValue,TEXT("%li"),&pPropVar->bVal);
  639. break;
  640. case VT_UI2:
  641. TSSCANF(szValue,TEXT("%li"),&pPropVar->uiVal);
  642. break;
  643. case VT_UI4:
  644. TSSCANF(szValue,TEXT("%li"),&pPropVar->ulVal);
  645. break;
  646. case VT_UI8:
  647. TSSCANF(szValue,TEXT("%li"),&pPropVar->lVal);
  648. break;
  649. case VT_INT:
  650. TSSCANF(szValue,TEXT("%li"),&pPropVar->intVal);
  651. break;
  652. case VT_R4:
  653. TSSCANF(szValue,TEXT("%f"),&pPropVar->fltVal);
  654. break;
  655. case VT_R8:
  656. TSSCANF(szValue,TEXT("%f"),&pPropVar->fltVal);
  657. break;
  658. case VT_BSTR:
  659. #ifndef UNICODE
  660. MultiByteToWideChar(CP_ACP, 0,szValue,-1,wszbuffer,MAX_PATH);
  661. pPropVar->bstrVal = SysAllocString(wszbuffer);
  662. #else
  663. pPropVar->bstrVal = SysAllocString(szValue);
  664. #endif
  665. break;
  666. case VT_CLSID:
  667. #ifndef UNICODE
  668. pPropVar->puuid = (GUID*)CoTaskMemAlloc(sizeof(UUID));
  669. UuidFromString((UCHAR*)szValue,pPropVar->puuid);
  670. #else
  671. pPropVar->puuid = CoTaskMemAlloc(sizeof(UUID));
  672. WideCharToMultiByte(CP_ACP, 0,szValue,-1,szbuffer,MAX_PATH,NULL,NULL);
  673. UuidFromString((UCHAR*)szbuffer,pPropVar->puuid);
  674. #endif
  675. break;
  676. case VT_UINT:
  677. TSSCANF(szValue,TEXT("%li"),&pPropVar->uintVal);
  678. break;
  679. case VT_VECTOR | VT_UI2:
  680. {
  681. TCHAR *psz = NULL;
  682. // is this a SYSTEMTIME formatted string?
  683. psz = TSTRSTR(szValue,TEXT(":"));
  684. if(NULL != psz){
  685. SYSTEMTIME *pSystemTime = NULL;
  686. pSystemTime = (SYSTEMTIME*)CoTaskMemAlloc(sizeof(SYSTEMTIME));
  687. if(pSystemTime){
  688. memset(pSystemTime,0,sizeof(SYSTEMTIME));
  689. // fill out SYSTEMTIME structure
  690. TSSCANF(szValue,TEXT("%hd:%hd:%hd:%hd:%hd:%hd:%hd:%hd"),&pSystemTime->wYear,
  691. &pSystemTime->wMonth,
  692. &pSystemTime->wDay,
  693. &pSystemTime->wDayOfWeek,
  694. &pSystemTime->wHour,
  695. &pSystemTime->wMinute,
  696. &pSystemTime->wSecond,
  697. &pSystemTime->wMilliseconds);
  698. // set count
  699. pPropVar->caui.cElems = (sizeof(SYSTEMTIME) / sizeof(WORD));
  700. // set pointer (array of WORD values)
  701. pPropVar->caui.pElems = (WORD*)pSystemTime;
  702. }
  703. }
  704. }
  705. break;
  706. default:
  707. TSSCANF(szValue,"%li",&pPropVar->lVal);
  708. break;
  709. }
  710. }
  711. void CWiatestView::OnSize(UINT nType, int cx, int cy)
  712. {
  713. CFormView::OnSize(nType, cx, cy);
  714. CRect ParentWindowRect;
  715. LONG lOffset = 0;
  716. // get parent window rect
  717. GetWindowRect(ParentWindowRect);
  718. ScreenToClient(ParentWindowRect);
  719. // resize property list control
  720. if(NULL != m_ItemPropertiesListCtrl.m_hWnd){
  721. CRect ListBoxRect;
  722. // get list control rect
  723. m_ItemPropertiesListCtrl.GetWindowRect(ListBoxRect);
  724. ScreenToClient(ListBoxRect);
  725. // adjust width
  726. ListBoxRect.right = ParentWindowRect.right - 10;
  727. lOffset = ListBoxRect.right;
  728. // adjust height
  729. ListBoxRect.bottom = ParentWindowRect.bottom - 10;
  730. m_ItemPropertiesListCtrl.MoveWindow(ListBoxRect);
  731. }
  732. if(GET_STIDEVICE_TYPE(m_lDeviceType) == StiDeviceTypeDigitalCamera){
  733. // move thumbnail control
  734. if(NULL != m_ThumbnailPreviewWindow.m_hWnd){
  735. CRect ThumbnailRect;
  736. // get thumbnail rect
  737. m_ThumbnailPreviewWindow.GetWindowRect(ThumbnailRect);
  738. ScreenToClient(ThumbnailRect);
  739. // adjust position
  740. INT iWidth = ThumbnailRect.Width();
  741. ThumbnailRect.right = lOffset;
  742. ThumbnailRect.left = (ThumbnailRect.right - iWidth);
  743. m_ThumbnailPreviewWindow.MoveWindow(ThumbnailRect);
  744. }
  745. // resize supported TYMED and Format listbox
  746. if(NULL != m_SupportedTymedAndFormatsListBox.m_hWnd){
  747. CRect ListBoxRect;
  748. CRect ThumbnailRect;
  749. // get list box rect
  750. m_SupportedTymedAndFormatsListBox.GetWindowRect(ListBoxRect);
  751. ScreenToClient(ListBoxRect);
  752. // get thumbnail rect
  753. m_ThumbnailPreviewWindow.GetWindowRect(ThumbnailRect);
  754. ScreenToClient(ThumbnailRect);
  755. // adjust width
  756. ListBoxRect.right = ThumbnailRect.left - 10;
  757. m_SupportedTymedAndFormatsListBox.MoveWindow(ListBoxRect);
  758. }
  759. } else {
  760. // resize supported TYMED listbox
  761. if(NULL != m_SupportedTymedAndFormatsListBox.m_hWnd){
  762. CRect ListBoxRect;
  763. CRect ThumbnailRect;
  764. // get list box rect
  765. m_SupportedTymedAndFormatsListBox.GetWindowRect(ListBoxRect);
  766. ScreenToClient(ListBoxRect);
  767. // adjust width
  768. ListBoxRect.right = lOffset;
  769. m_SupportedTymedAndFormatsListBox.MoveWindow(ListBoxRect);
  770. }
  771. }
  772. }
  773. void CWiatestView::OnDblclkItempropertiesListctrl(NMHDR* pNMHDR, LRESULT* pResult)
  774. {
  775. // find out what property is selected
  776. HD_NOTIFY* phdn = (HD_NOTIFY *) pNMHDR;
  777. TCHAR pszPropertyName[MAX_PATH];
  778. memset(pszPropertyName,0,sizeof(pszPropertyName));
  779. TCHAR pszPropertyValue[MAX_PATH];
  780. memset(pszPropertyValue,0,sizeof(pszPropertyValue));
  781. LV_ITEM lvitem;
  782. lvitem.mask = LVIF_PARAM;
  783. lvitem.iItem = phdn->iItem;
  784. lvitem.iSubItem = ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME;
  785. lvitem.pszText = NULL;
  786. // is an item selected?
  787. if (phdn->iItem < ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME)
  788. return;
  789. m_ItemPropertiesListCtrl.GetItem(&lvitem);
  790. // get stored property ID
  791. LONG iProp = 0;
  792. iProp = (LONG)lvitem.lParam;
  793. m_ItemPropertiesListCtrl.GetItemText(phdn->iItem,
  794. ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME,
  795. pszPropertyName,
  796. sizeof(pszPropertyName));
  797. m_ItemPropertiesListCtrl.GetItemText(phdn->iItem,
  798. ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYVALUE,
  799. pszPropertyValue,
  800. sizeof(pszPropertyValue));
  801. // get document
  802. CWiatestDoc* pDocument = NULL;
  803. pDocument = (CWiatestDoc*)m_pDocument;
  804. if(pDocument){
  805. IWiaPropertyStorage *pIWiaPropStg = NULL;
  806. HRESULT hr = S_OK;
  807. hr = pDocument->m_pICurrentItem->QueryInterface(IID_IWiaPropertyStorage,(void **)&pIWiaPropStg);
  808. if(SUCCEEDED(hr)) {
  809. // read property value for type and current value
  810. PROPVARIANT PropVar[1];
  811. PROPVARIANT AttrPropVar[1];
  812. PROPSPEC PropSpec[1];
  813. PropSpec[0].ulKind = PRSPEC_PROPID;
  814. PropSpec[0].propid = iProp;
  815. ULONG ulAttributes = 0;
  816. CWiaeditpropDlg PropertyEditDlg;
  817. hr = pIWiaPropStg->ReadMultiple(1,PropSpec,PropVar);
  818. if (S_OK == hr) {
  819. PropertyEditDlg.SetVarType(PropVar[0].vt);
  820. // clear variant
  821. PropVariantClear(PropVar);
  822. hr = pIWiaPropStg->GetPropertyAttributes(1, PropSpec,&ulAttributes,AttrPropVar);
  823. if(S_OK == hr){
  824. PropertyEditDlg.SetAttributes(ulAttributes, (PROPVARIANT*)AttrPropVar);
  825. BOOL bRefreshCurrentTYMEDAndFormatSelection = FALSE;
  826. if((lstrcmpi(pszPropertyName,TEXT("Format")) == 0) || (lstrcmpi(pszPropertyName,TEXT("Media Type")) == 0)){
  827. bRefreshCurrentTYMEDAndFormatSelection = TRUE;
  828. }
  829. if(PropertyEditDlg.DoModal(pszPropertyName,pszPropertyValue) == IDOK){
  830. memset(pszPropertyValue,0,sizeof(pszPropertyValue));
  831. PropertyEditDlg.GetPropertyValue(pszPropertyValue);
  832. PropVar[0].vt = PropertyEditDlg.GetVarType();
  833. TSTR2PROPVAR(pszPropertyValue,(PROPVARIANT*)PropVar);
  834. hr = pIWiaPropStg->WriteMultiple(1,PropSpec,PropVar,MIN_PROPID);
  835. if(S_OK == hr){
  836. // get current document, and refresh the property list with the current
  837. // selected item
  838. CWiatestDoc* pDocument = NULL;
  839. pDocument = (CWiatestDoc*)m_pDocument;
  840. if(pDocument){
  841. // update list control with properties
  842. AddWiaItemPropertiesToListControl(pDocument->m_pICurrentItem);
  843. if(bRefreshCurrentTYMEDAndFormatSelection){
  844. SetCurrentSelectionForTYMEDAndFormat();
  845. }
  846. }
  847. } else if FAILED(hr){
  848. // failure
  849. ErrorMessageBox(IDS_WIATESTERROR_WRITING_PROPERTY,hr);
  850. } else {
  851. // S_FALSE
  852. ErrorMessageBox(IDS_WIATESTWARNING_ADDITIONAL_PROPERTY);
  853. }
  854. // clear variant
  855. PropVariantClear(PropVar);
  856. } else {
  857. // user decided not to write the property
  858. }
  859. }
  860. }
  861. // release property storage
  862. pIWiaPropStg->Release();
  863. pIWiaPropStg = NULL;
  864. }
  865. }
  866. *pResult = 0;
  867. }
  868. void CWiatestView::AddSupportedTYMEDAndFormatsToListBox(IWiaItem *pIWiaItem)
  869. {
  870. m_SupportedTymedAndFormatsListBox.ResetContent();
  871. HRESULT hr = S_OK;
  872. IWiaDataTransfer *pIWiaDataTransfer = NULL;
  873. hr = pIWiaItem->QueryInterface(IID_IWiaDataTransfer, (void **)&pIWiaDataTransfer);
  874. if (S_OK == hr) {
  875. IEnumWIA_FORMAT_INFO *pIEnumWIA_FORMAT_INFO = NULL;
  876. WIA_FORMAT_INFO pfe;
  877. hr = pIWiaDataTransfer->idtEnumWIA_FORMAT_INFO(&pIEnumWIA_FORMAT_INFO);
  878. if (SUCCEEDED(hr)) {
  879. do {
  880. memset(&pfe,0,sizeof(pfe));
  881. hr = pIEnumWIA_FORMAT_INFO->Next(1, &pfe, NULL);
  882. if (hr == S_OK) {
  883. TCHAR szFormat[MAX_PATH];
  884. TCHAR szGuid[MAX_PATH];
  885. TCHAR szTYMED[MAX_PATH];
  886. memset(szFormat,0,sizeof(szFormat));
  887. memset(szGuid,0,sizeof(szGuid));
  888. memset(szTYMED,0,sizeof(szTYMED));
  889. if(!WIACONSTANT2TSTR(TEXT("Media Type"),(LONG)pfe.lTymed,szTYMED)){
  890. lstrcpy(szTYMED,TEXT("TYMED_UNKNOWN"));
  891. }
  892. FORMAT2TSTR(pfe.guidFormatID,szGuid);
  893. TSPRINTF(szFormat,TEXT("%s - %s"),szTYMED,szGuid);
  894. m_SupportedTymedAndFormatsListBox.AddString(szFormat);
  895. } else {
  896. if (FAILED(hr)) {
  897. ErrorMessageBox(IDS_WIATESTERROR_ENUMFORMATS,hr);
  898. }
  899. }
  900. } while (hr == S_OK);
  901. pIEnumWIA_FORMAT_INFO->Release();
  902. pIEnumWIA_FORMAT_INFO = NULL;
  903. } else {
  904. ErrorMessageBox(IDS_WIATESTERROR_ENUMFORMATS,hr);
  905. }
  906. pIWiaDataTransfer->Release();
  907. pIWiaDataTransfer = NULL;
  908. } else {
  909. ErrorMessageBox(IDS_WIATESTERROR_IWIADATATRANSFER,hr);
  910. }
  911. }
  912. void CWiatestView::FORMAT2TSTR(GUID guidFormat, TCHAR *pszFormat)
  913. {
  914. if(guidFormat == WiaImgFmt_UNDEFINED)
  915. lstrcpy(pszFormat,TEXT("WiaImgFmt_UNDEFINED:"));
  916. else if(guidFormat == WiaImgFmt_MEMORYBMP)
  917. lstrcpy(pszFormat,TEXT("WiaImgFmt_MEMORYBMP:"));
  918. else if(guidFormat == WiaImgFmt_BMP)
  919. lstrcpy(pszFormat,TEXT("WiaImgFmt_BMP:"));
  920. else if(guidFormat == WiaImgFmt_EMF)
  921. lstrcpy(pszFormat,TEXT("WiaImgFmt_EMF:"));
  922. else if(guidFormat == WiaImgFmt_WMF)
  923. lstrcpy(pszFormat,TEXT("WiaImgFmt_WMF:"));
  924. else if(guidFormat == WiaImgFmt_JPEG)
  925. lstrcpy(pszFormat,TEXT("WiaImgFmt_JPEG:"));
  926. else if(guidFormat == WiaImgFmt_PNG)
  927. lstrcpy(pszFormat,TEXT("WiaImgFmt_PNG:"));
  928. else if(guidFormat == WiaImgFmt_GIF)
  929. lstrcpy(pszFormat,TEXT("WiaImgFmt_GIF:"));
  930. else if(guidFormat == WiaImgFmt_TIFF)
  931. lstrcpy(pszFormat,TEXT("WiaImgFmt_TIFF:"));
  932. else if(guidFormat == WiaImgFmt_EXIF)
  933. lstrcpy(pszFormat,TEXT("WiaImgFmt_EXIF:"));
  934. else if(guidFormat == WiaImgFmt_PHOTOCD)
  935. lstrcpy(pszFormat,TEXT("WiaImgFmt_PHOTOCD:"));
  936. else if(guidFormat == WiaImgFmt_FLASHPIX)
  937. lstrcpy(pszFormat,TEXT("WiaImgFmt_FLASHPIX:"));
  938. else {
  939. lstrcpy(pszFormat,TEXT("Custom Format:"));
  940. }
  941. TCHAR szGUID[MAX_PATH];
  942. memset(szGUID,0,sizeof(szGUID));
  943. UCHAR *pwszUUID = NULL;
  944. UuidToString(&guidFormat,&pwszUUID);
  945. TSPRINTF(szGUID," (%s)",pwszUUID);
  946. lstrcat(pszFormat,szGUID);
  947. // free allocated string
  948. RpcStringFree(&pwszUUID);
  949. }
  950. void CWiatestView::OnAcquireimage()
  951. {
  952. // delete old temp image files
  953. DeleteTempDataTransferFiles();
  954. CWiatestDoc* pDocument = NULL;
  955. pDocument = (CWiatestDoc*)m_pDocument;
  956. if(pDocument){
  957. if(pDocument->m_pICurrentItem == pDocument->m_pIRootItem){
  958. // use the common UI, because we can not transfer from the root item
  959. OnAcquireimageCommonui();
  960. return;
  961. }
  962. TCHAR szFileName[MAX_PATH];
  963. TCHAR szTempFile[MAX_PATH];
  964. memset(szFileName,0,sizeof(szFileName));
  965. memset(szTempFile,0,sizeof(szTempFile));
  966. CWiahelper WIA;
  967. HRESULT hr = S_OK;
  968. LONG lTymed = 0;
  969. hr = WIA.SetIWiaItem(pDocument->m_pICurrentItem);
  970. if (SUCCEEDED(hr)) {
  971. hr = WIA.ReadPropertyLong(WIA_IPA_TYMED,&lTymed);
  972. if (S_OK == hr) {
  973. switch (lTymed) {
  974. case TYMED_CALLBACK:
  975. case TYMED_MULTIPAGE_CALLBACK:
  976. GetTempPath(sizeof(szFileName),szFileName);
  977. RC2TSTR(IDS_WIATEST_MEMORYTRANSFER_FILENAME,szTempFile,sizeof(szTempFile));
  978. lstrcat(szFileName,szTempFile);
  979. hr = TransferToMemory(szFileName, pDocument->m_pICurrentItem);
  980. break;
  981. case TYMED_FILE:
  982. case TYMED_MULTIPAGE_FILE:
  983. GetTempPath(sizeof(szFileName),szFileName);
  984. RC2TSTR(IDS_WIATEST_FILETRANSFER_FILENAME,szTempFile,sizeof(szTempFile));
  985. lstrcat(szFileName,szTempFile);
  986. hr = TransferToFile(szFileName,pDocument->m_pICurrentItem);
  987. break;
  988. default:
  989. ErrorMessageBox(IDS_WIATESTERROR_UNSUPPORTEDTYMED);
  990. break;
  991. }
  992. } else if (S_FALSE == hr) {
  993. ErrorMessageBox(IDS_WIATESTERROR_READINGTYMED_EXIST,hr);
  994. } else {
  995. ErrorMessageBox(IDS_WIATESTERROR_READINGTYMED,hr);
  996. }
  997. } else {
  998. ErrorMessageBox(IDS_WIATESTERROR_READINGTYMED,hr);
  999. }
  1000. if ((hr == S_OK)||(WIA_STATUS_END_OF_MEDIA == hr)) {
  1001. CWiahelper WIA;
  1002. WIA.SetIWiaItem(pDocument->m_pICurrentItem);
  1003. GUID guidFormat;
  1004. memset(&guidFormat,0,sizeof(guidFormat));
  1005. hr = WIA.ReadPropertyGUID(WIA_IPA_FORMAT,&guidFormat);
  1006. if(S_OK == hr){
  1007. RenameTempDataTransferFilesAndLaunchViewer(guidFormat,lTymed);
  1008. }
  1009. }
  1010. }
  1011. }
  1012. HRESULT CWiatestView::TransferToFile(TCHAR *szFileName, IWiaItem *pIWiaItem)
  1013. {
  1014. STGMEDIUM StgMedium;
  1015. HRESULT hr = S_OK;
  1016. // get IWiaDatatransfer interface
  1017. IWiaDataTransfer *pIWiaDataTransfer = NULL;
  1018. hr = pIWiaItem->QueryInterface(IID_IWiaDataTransfer, (void **)&pIWiaDataTransfer);
  1019. if (SUCCEEDED(hr)) {
  1020. WCHAR wszFileName[MAX_PATH];
  1021. memset(wszFileName,0,sizeof(wszFileName));
  1022. #ifndef UNICODE
  1023. MultiByteToWideChar(CP_ACP, 0,szFileName,-1,wszFileName,MAX_PATH);
  1024. #else
  1025. lstrcpy(wszFileName,szFileName);
  1026. #endif
  1027. CWiahelper WIA;
  1028. LONG lTymed = TYMED_FILE;
  1029. WIA.SetIWiaItem(pIWiaItem);
  1030. hr = WIA.ReadPropertyLong(WIA_IPA_TYMED, &lTymed);
  1031. if (SUCCEEDED(hr)) {
  1032. StgMedium.tymed = lTymed;
  1033. StgMedium.pUnkForRelease = NULL;
  1034. StgMedium.hGlobal = NULL;
  1035. StgMedium.lpszFileName = wszFileName;
  1036. IWiaDataCallback* pIWiaDataCallback = NULL;
  1037. CWiaDataCallback WiaDataCallback;
  1038. hr = WiaDataCallback.QueryInterface(IID_IWiaDataCallback,(void **)&pIWiaDataCallback);
  1039. if (hr == S_OK) {
  1040. hr = pIWiaDataTransfer->idtGetData(&StgMedium,pIWiaDataCallback);
  1041. if ((hr == S_OK)||(WIA_STATUS_END_OF_MEDIA == hr)) {
  1042. // successful transfer
  1043. } else if (S_FALSE == hr) {
  1044. ErrorMessageBox(IDS_WIATESTERROR_CANCEL_ACQUISITION);
  1045. } else {
  1046. ErrorMessageBox(IDS_WIATESTERROR_ACQUISITION,hr);
  1047. }
  1048. pIWiaDataTransfer->Release();
  1049. //WiaDataCallback.Release();
  1050. }
  1051. }
  1052. }
  1053. return hr;
  1054. }
  1055. HRESULT CWiatestView::TransferToMemory(TCHAR *szFileName, IWiaItem *pIWiaItem)
  1056. {
  1057. HRESULT hr = S_OK;
  1058. // get IWiaDatatransfer interface
  1059. IWiaDataTransfer *pIWiaDataTransfer = NULL;
  1060. hr = pIWiaItem->QueryInterface(IID_IWiaDataTransfer, (void **)&pIWiaDataTransfer);
  1061. if (SUCCEEDED(hr)) {
  1062. WIA_DATA_TRANSFER_INFO WiaDataTransferInformation;
  1063. memset(&WiaDataTransferInformation,0,sizeof(WiaDataTransferInformation));
  1064. WiaDataTransferInformation.ulSize = sizeof(WiaDataTransferInformation);
  1065. WiaDataTransferInformation.ulBufferSize = (ReadMinBufferSizeProperty(pIWiaItem) * MIN_BUFFER_FACTOR);
  1066. IWiaDataCallback* pIWiaDataCallback = NULL;
  1067. CWiaDataCallback WiaDataCallback;
  1068. hr = WiaDataCallback.QueryInterface(IID_IWiaDataCallback,(void **)&pIWiaDataCallback);
  1069. if (hr == S_OK) {
  1070. hr = pIWiaDataTransfer->idtGetBandedData(&WiaDataTransferInformation,pIWiaDataCallback);
  1071. if ((hr == S_OK)||(WIA_STATUS_END_OF_MEDIA == hr)) {
  1072. HANDLE hMemoryDataFile = NULL;
  1073. hMemoryDataFile = CreateFile(szFileName,
  1074. GENERIC_WRITE,FILE_SHARE_READ,NULL,
  1075. CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  1076. if (hMemoryDataFile != INVALID_HANDLE_VALUE && hMemoryDataFile != NULL) {
  1077. LONG lDataSize = 0;
  1078. BYTE *pData = WiaDataCallback.GetCallbackMemoryPtr(&lDataSize);
  1079. DWORD dwBytesWritten = 0;
  1080. if (lDataSize > 0) {
  1081. // handle BITMAP DATA (special case)
  1082. if (WiaDataCallback.IsBITMAPDATA()) {
  1083. // we need to adjust any headers, because the height and image size information
  1084. // could be incorrect. (this will handle infinite page length devices)
  1085. BITMAPFILEHEADER bmfh;
  1086. BITMAPINFOHEADER *pbmh = NULL;
  1087. pbmh = (BITMAPINFOHEADER*)pData;
  1088. if(pbmh->biHeight < 0){
  1089. StatusMessageBox(IDS_WIATESTWARNING_NEGATIVE_HEIGHTBITMAP);
  1090. pbmh->biHeight = abs(pbmh->biHeight);
  1091. }
  1092. LONG lPaletteSize = pbmh->biClrUsed * sizeof(RGBQUAD);
  1093. bmfh.bfType = BMPFILE_HEADER_MARKER;
  1094. bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + lPaletteSize;
  1095. bmfh.bfSize = sizeof(BITMAPFILEHEADER) + lDataSize;
  1096. bmfh.bfReserved1 = 0;
  1097. bmfh.bfReserved2 = 0;
  1098. // only fix the BITMAPINFOHEADER if height needs to be calculated
  1099. if (pbmh->biHeight == 0) {
  1100. StatusMessageBox(IDS_WIATESTWARNING_ZERO_HEIGHTBITMAP);
  1101. LONG lWidthBytes = CalculateWidthBytes(pbmh->biWidth,pbmh->biBitCount);
  1102. pbmh->biSizeImage = lDataSize - lPaletteSize - sizeof(BITMAPINFOHEADER);
  1103. pbmh->biHeight = LONG(pbmh->biSizeImage/lWidthBytes);
  1104. pbmh->biXPelsPerMeter = 0; // zero out
  1105. pbmh->biYPelsPerMeter = 0; // zero out
  1106. }
  1107. WriteFile(hMemoryDataFile,&bmfh,sizeof(bmfh),&dwBytesWritten,NULL);
  1108. }
  1109. // write data to disk
  1110. WriteFile(hMemoryDataFile,pData,lDataSize,&dwBytesWritten,NULL);
  1111. }
  1112. // flush and close
  1113. FlushFileBuffers(hMemoryDataFile);
  1114. CloseHandle(hMemoryDataFile);
  1115. }
  1116. } else if (S_FALSE == hr) {
  1117. ErrorMessageBox(IDS_WIATESTERROR_CANCEL_ACQUISITION);
  1118. } else {
  1119. ErrorMessageBox(IDS_WIATESTERROR_ACQUISITION,hr);
  1120. }
  1121. pIWiaDataTransfer->Release();
  1122. //WiaDataCallback.Release();
  1123. }
  1124. }
  1125. return hr;
  1126. }
  1127. void CWiatestView::OnLoadWiapropertystream()
  1128. {
  1129. CWiatestDoc* pDocument = NULL;
  1130. pDocument = (CWiatestDoc*)m_pDocument;
  1131. if(pDocument){
  1132. CWiahelper WIA;
  1133. WIA.SetIWiaItem(pDocument->m_pICurrentItem);
  1134. HRESULT hr = S_OK;
  1135. TCHAR szPropertyStreamFile[MAX_PATH];
  1136. memset(szPropertyStreamFile,0,sizeof(szPropertyStreamFile));
  1137. // select saving location
  1138. OPENFILENAME ofn; // common dialog box structure
  1139. TCHAR szLoadPropStreamTitle[MAX_PATH];
  1140. memset(szLoadPropStreamTitle,0,sizeof(szLoadPropStreamTitle));
  1141. RC2TSTR(IDS_WIATESTLOADPROPSTREAM_DIALOGTITLE,szLoadPropStreamTitle,sizeof(szLoadPropStreamTitle));
  1142. memset(&ofn,0,sizeof(OPENFILENAME));
  1143. ofn.lStructSize = sizeof(OPENFILENAME);
  1144. ofn.hwndOwner = m_hWnd;
  1145. ofn.lpstrFile = szPropertyStreamFile;
  1146. ofn.nMaxFile = sizeof(szPropertyStreamFile);
  1147. ofn.lpstrFilter = "*.wia\0*.wia\0";
  1148. ofn.nFilterIndex = 1;
  1149. ofn.lpstrFileTitle = NULL;
  1150. ofn.nMaxFileTitle = 0;
  1151. ofn.lpstrInitialDir = NULL;
  1152. ofn.lpstrTitle = szLoadPropStreamTitle;
  1153. ofn.Flags = 0;
  1154. ofn.lpstrDefExt = "wia";
  1155. if (!GetOpenFileName(&ofn)) {
  1156. return;
  1157. }
  1158. hr = WIA.ReadPropertyStreamFile(szPropertyStreamFile);
  1159. if(FAILED(hr)){
  1160. ErrorMessageBox(IDS_WIATESTERROR_READPROPERTYSTREAMFILE,hr);
  1161. } else {
  1162. // refresh the item tree
  1163. AddWiaItemsToTreeControl(TVI_ROOT,pDocument->m_pIRootItem);
  1164. // refresh the properties
  1165. AddWiaItemPropertiesToListControl(pDocument->m_pIRootItem);
  1166. }
  1167. }
  1168. }
  1169. void CWiatestView::OnSaveWiapropertystream()
  1170. {
  1171. CWiatestDoc* pDocument = NULL;
  1172. pDocument = (CWiatestDoc*)m_pDocument;
  1173. if(pDocument){
  1174. CWiahelper WIA;
  1175. WIA.SetIWiaItem(pDocument->m_pICurrentItem);
  1176. HRESULT hr = S_OK;
  1177. TCHAR szPropertyStreamFile[MAX_PATH];
  1178. memset(szPropertyStreamFile,0,sizeof(szPropertyStreamFile));
  1179. // select saving location
  1180. OPENFILENAME ofn; // common dialog box structure
  1181. TCHAR szSavePropStreamTitle[MAX_PATH];
  1182. memset(szSavePropStreamTitle,0,sizeof(szSavePropStreamTitle));
  1183. RC2TSTR(IDS_WIATESTSAVEPROPSTREAM_DIALOGTITLE,szSavePropStreamTitle,sizeof(szSavePropStreamTitle));
  1184. memset(&ofn,0,sizeof(OPENFILENAME));
  1185. ofn.lStructSize = sizeof(OPENFILENAME);
  1186. ofn.hwndOwner = m_hWnd;
  1187. ofn.lpstrFile = szPropertyStreamFile;
  1188. ofn.nMaxFile = sizeof(szPropertyStreamFile);
  1189. ofn.lpstrFilter = "*.wia\0*.wia\0";
  1190. ofn.nFilterIndex = 1;
  1191. ofn.lpstrFileTitle = NULL;
  1192. ofn.nMaxFileTitle = 0;
  1193. ofn.lpstrInitialDir = NULL;
  1194. ofn.lpstrTitle = szSavePropStreamTitle;
  1195. ofn.Flags = 0;
  1196. ofn.lpstrDefExt = "wia";
  1197. if (!GetSaveFileName(&ofn)) {
  1198. return;
  1199. }
  1200. hr = WIA.WritePropertyStreamFile(szPropertyStreamFile);
  1201. if(FAILED(hr)){
  1202. ErrorMessageBox(IDS_WIATESTERROR_WRITEPROPERTYSTREAMFILE,hr);
  1203. }
  1204. }
  1205. }
  1206. void CWiatestView::OnRclickItempropertiesListctrl(NMHDR* pNMHDR, LRESULT* pResult)
  1207. {
  1208. POINT MousePos;
  1209. CMenu PopupMenu;
  1210. CMenu *pEditMenu = NULL;
  1211. if(PopupMenu.LoadMenu(IDR_PROPERTY_EDIT_POPUPMENU)){
  1212. GetCursorPos(&MousePos);
  1213. pEditMenu = PopupMenu.GetSubMenu(0);
  1214. if(pEditMenu){
  1215. pEditMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON, MousePos.x, MousePos.y, this);
  1216. }
  1217. }
  1218. *pResult = 0;
  1219. }
  1220. void CWiatestView::OnPropertyeditpopupmenuEditpropertyvalue()
  1221. {
  1222. PROPVARIANT *pPropertyVariants = NULL;
  1223. PROPSPEC *pPropertySpecs = NULL;
  1224. UINT uiNumProperties = m_ItemPropertiesListCtrl.GetSelectedCount();
  1225. if(uiNumProperties <=0){
  1226. return;
  1227. }
  1228. BOOL bWriteProperties = TRUE;
  1229. IWiaPropertyStorage *pIWiaPropStg = NULL;
  1230. HRESULT hr = S_OK;
  1231. UINT iPropertyIndex = 0;
  1232. pPropertyVariants = new PROPVARIANT[uiNumProperties];
  1233. if(pPropertyVariants){
  1234. pPropertySpecs = new PROPSPEC[uiNumProperties];
  1235. if(pPropertySpecs){
  1236. POSITION pos = NULL;
  1237. pos = m_ItemPropertiesListCtrl.GetFirstSelectedItemPosition();
  1238. if (NULL != pos){
  1239. while (pos && bWriteProperties){
  1240. int iItem = m_ItemPropertiesListCtrl.GetNextSelectedItem(pos);
  1241. // find out what property is selected
  1242. TCHAR pszPropertyName[MAX_PATH];
  1243. memset(pszPropertyName,0,sizeof(pszPropertyName));
  1244. TCHAR pszPropertyValue[MAX_PATH];
  1245. memset(pszPropertyValue,0,sizeof(pszPropertyValue));
  1246. LV_ITEM lvitem;
  1247. lvitem.mask = LVIF_PARAM;
  1248. lvitem.iItem = iItem;
  1249. lvitem.iSubItem = ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME;
  1250. lvitem.pszText = NULL;
  1251. // is an item selected?
  1252. if (iItem < ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME)
  1253. return;
  1254. m_ItemPropertiesListCtrl.GetItem(&lvitem);
  1255. // get stored property ID
  1256. LONG iProp = 0;
  1257. iProp = (LONG)lvitem.lParam;
  1258. m_ItemPropertiesListCtrl.GetItemText(iItem,
  1259. ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYNAME,
  1260. pszPropertyName,
  1261. sizeof(pszPropertyName));
  1262. m_ItemPropertiesListCtrl.GetItemText(iItem,
  1263. ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYVALUE,
  1264. pszPropertyValue,
  1265. sizeof(pszPropertyValue));
  1266. // get document
  1267. CWiatestDoc* pDocument = NULL;
  1268. pDocument = (CWiatestDoc*)m_pDocument;
  1269. if(pDocument){
  1270. hr = pDocument->m_pICurrentItem->QueryInterface(IID_IWiaPropertyStorage,(void **)&pIWiaPropStg);
  1271. if(SUCCEEDED(hr)) {
  1272. // read property value for type and current value
  1273. PROPVARIANT PropVar[1];
  1274. PROPVARIANT AttrPropVar[1];
  1275. PROPSPEC PropSpec[1];
  1276. PropSpec[0].ulKind = PRSPEC_PROPID;
  1277. PropSpec[0].propid = iProp;
  1278. // set propspec
  1279. pPropertySpecs[iPropertyIndex].ulKind = PRSPEC_PROPID;
  1280. pPropertySpecs[iPropertyIndex].propid = iProp;
  1281. ULONG ulAttributes = 0;
  1282. CWiaeditpropDlg PropertyEditDlg;
  1283. hr = pIWiaPropStg->ReadMultiple(1,PropSpec,PropVar);
  1284. if (S_OK == hr) {
  1285. PropertyEditDlg.SetVarType(PropVar[0].vt);
  1286. // clear variant
  1287. PropVariantClear(PropVar);
  1288. hr = pIWiaPropStg->GetPropertyAttributes(1, PropSpec,&ulAttributes,AttrPropVar);
  1289. if(S_OK == hr){
  1290. PropertyEditDlg.SetAttributes(ulAttributes, (PROPVARIANT*)AttrPropVar);
  1291. if(PropertyEditDlg.DoModal(pszPropertyName,pszPropertyValue) == IDOK){
  1292. memset(pszPropertyValue,0,sizeof(pszPropertyValue));
  1293. PropertyEditDlg.GetPropertyValue(pszPropertyValue);
  1294. // set variant
  1295. pPropertyVariants[iPropertyIndex].vt = PropertyEditDlg.GetVarType();
  1296. TSTR2PROPVAR(pszPropertyValue,(PROPVARIANT*)&pPropertyVariants[iPropertyIndex]);
  1297. iPropertyIndex++;
  1298. } else {
  1299. // user decided not to write the property
  1300. bWriteProperties = FALSE;
  1301. }
  1302. }
  1303. }
  1304. // release property storage
  1305. pIWiaPropStg->Release();
  1306. pIWiaPropStg = NULL;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. if(bWriteProperties){
  1313. // get current document, and refresh the property list with the current
  1314. // selected item
  1315. CWiatestDoc* pDocument = NULL;
  1316. pDocument = (CWiatestDoc*)m_pDocument;
  1317. if(pDocument){
  1318. hr = pDocument->m_pICurrentItem->QueryInterface(IID_IWiaPropertyStorage,(void **)&pIWiaPropStg);
  1319. if(SUCCEEDED(hr)) {
  1320. hr = pIWiaPropStg->WriteMultiple(uiNumProperties,pPropertySpecs,pPropertyVariants,MIN_PROPID);
  1321. if(S_OK == hr){
  1322. // success
  1323. } else if FAILED(hr){
  1324. // failure
  1325. ErrorMessageBox(IDS_WIATESTERROR_WRITING_PROPERTY,hr);
  1326. } else {
  1327. // S_FALSE
  1328. ErrorMessageBox(IDS_WIATESTWARNING_ADDITIONAL_PROPERTY);
  1329. }
  1330. pIWiaPropStg->Release();
  1331. pIWiaPropStg = NULL;
  1332. }
  1333. // update list control with properties
  1334. AddWiaItemPropertiesToListControl(pDocument->m_pICurrentItem);
  1335. // update TYMED and format selection listbox
  1336. SetCurrentSelectionForTYMEDAndFormat();
  1337. }
  1338. }
  1339. if(pPropertyVariants){
  1340. PropVariantClear(pPropertyVariants);
  1341. delete [] pPropertyVariants;
  1342. pPropertyVariants = NULL;
  1343. }
  1344. if(pPropertySpecs){
  1345. delete [] pPropertySpecs;
  1346. pPropertySpecs = NULL;
  1347. }
  1348. }
  1349. }
  1350. void CWiatestView::OnViewCapabilities()
  1351. {
  1352. CWiacapDlg CapabilitiesDlg;
  1353. CWiatestDoc* pDocument = NULL;
  1354. pDocument = (CWiatestDoc*)m_pDocument;
  1355. if(pDocument){
  1356. CapabilitiesDlg.SetIWiaItem(pDocument->m_pIRootItem);
  1357. CapabilitiesDlg.DoModal();
  1358. #ifdef FORCE_UPDATE
  1359. if(CapabilitiesDlg.m_bCommandSent){
  1360. // refresh the item tree
  1361. AddWiaItemsToTreeControl(TVI_ROOT,pDocument->m_pIRootItem);
  1362. // refresh the properties
  1363. AddWiaItemPropertiesToListControl(pDocument->m_pIRootItem);
  1364. }
  1365. #endif
  1366. }
  1367. }
  1368. void CWiatestView::OnRclickItemTreectrl(NMHDR* pNMHDR, LRESULT* pResult)
  1369. {
  1370. POINT MousePos;
  1371. CMenu PopupMenu;
  1372. CMenu *pEditMenu = NULL;
  1373. if(PopupMenu.LoadMenu(IDR_ITEMTREE_POPUPMENU)){
  1374. GetCursorPos(&MousePos);
  1375. pEditMenu = PopupMenu.GetSubMenu(0);
  1376. if(pEditMenu){
  1377. CWiatestDoc* pDocument = NULL;
  1378. pDocument = (CWiatestDoc*)m_pDocument;
  1379. if(pDocument){
  1380. if(pDocument->m_pICurrentItem == pDocument->m_pIRootItem){
  1381. pEditMenu->EnableMenuItem(IDM_DELETE_ITEM,MF_BYCOMMAND|MF_GRAYED);
  1382. pEditMenu->RemoveMenu(IDM_ACQUIREIMAGE,MF_BYCOMMAND);
  1383. } else {
  1384. pEditMenu->RemoveMenu(IDM_ACQUIREIMAGE_COMMONUI,MF_BYCOMMAND);
  1385. }
  1386. pEditMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON, MousePos.x, MousePos.y, this);
  1387. }
  1388. }
  1389. }
  1390. *pResult = 0;
  1391. }
  1392. ULONG CWiatestView::ReadMinBufferSizeProperty(IWiaItem *pIWiaItem)
  1393. {
  1394. LONG lMinBufferSize = 0;
  1395. CWiahelper WIA;
  1396. WIA.SetIWiaItem(pIWiaItem);
  1397. HRESULT hr = S_OK;
  1398. hr = WIA.ReadPropertyLong(WIA_IPA_MIN_BUFFER_SIZE,&lMinBufferSize);
  1399. if(FAILED(hr)){
  1400. ErrorMessageBox(IDS_WIATESTERROR_READINGMINBUFFERSIZE,hr);
  1401. }
  1402. return lMinBufferSize;
  1403. }
  1404. void CWiatestView::SetCurrentSelectionForTYMEDAndFormat()
  1405. {
  1406. TCHAR szTymed[MAX_PATH];
  1407. memset(szTymed,0,sizeof(szTymed));
  1408. TCHAR szFormat[MAX_PATH];
  1409. memset(szFormat,0,sizeof(szFormat));
  1410. INT iItem = 0;
  1411. LVFINDINFO info;
  1412. info.flags = LVFI_PARTIAL|LVFI_STRING;
  1413. // find current TYMED setting
  1414. info.psz = TEXT("Media Type");
  1415. iItem = m_ItemPropertiesListCtrl.FindItem(&info,-1);
  1416. if(iItem != -1){
  1417. // item Found
  1418. // get current value from control
  1419. m_ItemPropertiesListCtrl.GetItemText(iItem,ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYVALUE,
  1420. szTymed, sizeof(szTymed));
  1421. LONG lTymed = 0;
  1422. TSSCANF(szTymed,"%d",&lTymed);
  1423. WIACONSTANT2TSTR(TEXT("Media Type"), lTymed, szTymed);
  1424. }
  1425. // find current Format setting
  1426. info.psz = TEXT("Format");
  1427. iItem = m_ItemPropertiesListCtrl.FindItem(&info,-1);
  1428. if(iItem != -1){
  1429. // item Found
  1430. // get current value from control
  1431. m_ItemPropertiesListCtrl.GetItemText(iItem,ITEMPROPERTYLISTCTRL_COLUMN_PROPERTYVALUE,
  1432. szFormat, sizeof(szFormat));
  1433. }
  1434. // find and select the current TYMED / format pair in the selection control.
  1435. INT iNumListBoxItems = 0;
  1436. iNumListBoxItems = m_SupportedTymedAndFormatsListBox.GetCount();
  1437. if(iNumListBoxItems > 0){
  1438. for(INT i = 0; i < iNumListBoxItems; i++){
  1439. TCHAR szText[MAX_PATH];
  1440. memset(szText,0,sizeof(szText));
  1441. m_SupportedTymedAndFormatsListBox.GetText(i,szText);
  1442. if(TSTRSTR(szText,szTymed) != NULL){
  1443. // found TYMED
  1444. if(TSTRSTR(szText,szFormat) != NULL){
  1445. // found format
  1446. m_SupportedTymedAndFormatsListBox.SetCurSel(i);
  1447. // exit loop
  1448. i = iNumListBoxItems;
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. void CWiatestView::DeleteTempDataTransferFiles()
  1455. {
  1456. }
  1457. void CWiatestView::RenameTempDataTransferFilesAndLaunchViewer(GUID guidFormat, LONG lTymed)
  1458. {
  1459. TCHAR *pszFileExt = NULL;
  1460. TCHAR szOriginalFileName[MAX_PATH];
  1461. TCHAR szFileName[MAX_PATH];
  1462. TCHAR szTempPath[MAX_PATH];
  1463. TCHAR szFullLaunchPath[MAX_PATH];
  1464. TCHAR szOriginalFullLaunchPath[MAX_PATH];
  1465. memset(szFileName,0,sizeof(szFileName));
  1466. memset(szTempPath,0,sizeof(szTempPath));
  1467. memset(szFullLaunchPath,0,sizeof(szFullLaunchPath));
  1468. memset(szOriginalFileName,0,sizeof(szOriginalFileName));
  1469. memset(szOriginalFullLaunchPath,0,sizeof(szOriginalFullLaunchPath));
  1470. GetTempPath(sizeof(szTempPath),szTempPath);
  1471. BOOL bKnownFormat = TRUE;
  1472. switch(lTymed){
  1473. case TYMED_CALLBACK:
  1474. case TYMED_MULTIPAGE_CALLBACK:
  1475. RC2TSTR(IDS_WIATEST_MEMORYTRANSFER_FILENAME,szOriginalFileName,sizeof(szOriginalFileName));
  1476. lstrcpy(szFileName,szOriginalFileName);
  1477. pszFileExt = TSTRSTR(szFileName,TEXT("mem"));
  1478. break;
  1479. case TYMED_FILE:
  1480. case TYMED_MULTIPAGE_FILE:
  1481. RC2TSTR(IDS_WIATEST_FILETRANSFER_FILENAME,szOriginalFileName,sizeof(szOriginalFileName));
  1482. lstrcpy(szFileName,szOriginalFileName);
  1483. pszFileExt = TSTRSTR(szFileName,TEXT("fil"));
  1484. break;
  1485. default:
  1486. break;
  1487. }
  1488. if(lstrlen(szFileName) > 0){
  1489. if(pszFileExt){
  1490. // rename to known image formats
  1491. if(guidFormat == WiaImgFmt_UNDEFINED)
  1492. lstrcpy(pszFileExt,TEXT("bmp"));
  1493. else if(guidFormat == WiaImgFmt_MEMORYBMP)
  1494. lstrcpy(pszFileExt,TEXT("bmp"));
  1495. else if(guidFormat == WiaImgFmt_BMP)
  1496. lstrcpy(pszFileExt,TEXT("bmp"));
  1497. else if(guidFormat == WiaImgFmt_EMF)
  1498. lstrcpy(pszFileExt,TEXT("emf"));
  1499. else if(guidFormat == WiaImgFmt_WMF)
  1500. lstrcpy(pszFileExt,TEXT("wmf"));
  1501. else if(guidFormat == WiaImgFmt_JPEG)
  1502. lstrcpy(pszFileExt,TEXT("jpg"));
  1503. else if(guidFormat == WiaImgFmt_PNG)
  1504. lstrcpy(pszFileExt,TEXT("png"));
  1505. else if(guidFormat == WiaImgFmt_GIF)
  1506. lstrcpy(pszFileExt,TEXT("gif"));
  1507. else if(guidFormat == WiaImgFmt_TIFF)
  1508. lstrcpy(pszFileExt,TEXT("tif"));
  1509. else if(guidFormat == WiaImgFmt_EXIF)
  1510. lstrcpy(pszFileExt,TEXT("jpg"));
  1511. else if(guidFormat == WiaImgFmt_PHOTOCD)
  1512. lstrcpy(pszFileExt,TEXT("pcd"));
  1513. else if(guidFormat == WiaImgFmt_FLASHPIX)
  1514. lstrcpy(pszFileExt,TEXT("fpx"));
  1515. else {
  1516. TCHAR szValue[MAX_PATH];
  1517. memset(szValue,0,sizeof(szValue));
  1518. UCHAR *pwszUUID = NULL;
  1519. UuidToString(&guidFormat,&pwszUUID);
  1520. TSPRINTF(szValue,TEXT("%s"),pwszUUID);
  1521. // (TEXT("(Unknown Image type) GUID: %s"),pwszUUID);
  1522. // free allocated string
  1523. RpcStringFree(&pwszUUID);
  1524. bKnownFormat = FALSE;
  1525. }
  1526. }
  1527. }
  1528. if(bKnownFormat){
  1529. // launch viewer
  1530. lstrcpy(szFullLaunchPath,szTempPath);
  1531. lstrcat(szFullLaunchPath,szFileName);
  1532. lstrcpy(szOriginalFullLaunchPath,szTempPath);
  1533. lstrcat(szOriginalFullLaunchPath,szOriginalFileName);
  1534. // delete any duplicates
  1535. DeleteFile(szFullLaunchPath);
  1536. // rename file
  1537. MoveFile(szOriginalFullLaunchPath,szFullLaunchPath);
  1538. HINSTANCE hInst = NULL;
  1539. hInst = ShellExecute(m_hWnd,NULL,szFullLaunchPath,NULL,szTempPath,SW_SHOW);
  1540. } else {
  1541. ErrorMessageBox(IDS_WIATESTERROR_UNKNOWN_IMAGEFORMAT);
  1542. }
  1543. }
  1544. LONG CWiatestView::CalculateWidthBytes(LONG lWidthPixels, LONG lbpp)
  1545. {
  1546. LONG lWidthBytes = 0;
  1547. lWidthBytes = (lWidthPixels * lbpp) + 31;
  1548. lWidthBytes = ((lWidthBytes/8) & 0xfffffffc);
  1549. return lWidthBytes;
  1550. }
  1551. void CWiatestView::OnDeleteItem()
  1552. {
  1553. HRESULT hr = S_OK;
  1554. CWiatestDoc* pDocument = NULL;
  1555. pDocument = (CWiatestDoc*)m_pDocument;
  1556. if(pDocument){
  1557. if(pDocument->m_pICurrentItem != pDocument->m_pIRootItem){
  1558. pDocument->m_pICurrentItem->DeleteItem(0);
  1559. pDocument->m_pICurrentItem->Release();
  1560. pDocument->m_pICurrentItem = NULL;
  1561. // refresh the item tree
  1562. AddWiaItemsToTreeControl(TVI_ROOT,pDocument->m_pIRootItem);
  1563. // refresh the properties
  1564. AddWiaItemPropertiesToListControl(pDocument->m_pIRootItem);
  1565. } else {
  1566. ErrorMessageBox(IDS_WIATESTERROR_DELETEROOTITEM);
  1567. }
  1568. }
  1569. }
  1570. void CWiatestView::OnAcquireimageCommonui()
  1571. {
  1572. // delete old temp image files
  1573. DeleteTempDataTransferFiles();
  1574. HRESULT hr = S_OK;
  1575. IWiaItem **pIWiaItemArray = NULL;
  1576. LONG lItemCount = 0;
  1577. CWiatestDoc* pDocument = NULL;
  1578. pDocument = (CWiatestDoc*)m_pDocument;
  1579. if(pDocument){
  1580. hr = pDocument->m_pIRootItem->DeviceDlg(m_hWnd,0,WIA_INTENT_MINIMIZE_SIZE,&lItemCount,&pIWiaItemArray);
  1581. if(S_OK == hr){
  1582. // get temp file name
  1583. TCHAR szTempFile[MAX_PATH];
  1584. memset(szTempFile,0,sizeof(szTempFile));
  1585. RC2TSTR(IDS_WIATEST_FILETRANSFER_FILENAME,szTempFile,sizeof(szTempFile));
  1586. for(LONG lItem = 0; lItem < lItemCount; lItem++){
  1587. // get temp path
  1588. TCHAR szFileName[MAX_PATH];
  1589. memset(szFileName,0,sizeof(szFileName));
  1590. GetTempPath(sizeof(szFileName),szFileName);
  1591. // create new temp file with image index number
  1592. TCHAR szFinalFileName[MAX_PATH];
  1593. memset(szFinalFileName,0,sizeof(szFinalFileName));
  1594. TSPRINTF(szFinalFileName,TEXT("%d%s"),lItem,szTempFile);
  1595. // add new temp file to temp path
  1596. lstrcat(szFileName,szFinalFileName);
  1597. // set TYMED_FILE
  1598. CWiahelper WIA;
  1599. WIA.SetIWiaItem(pIWiaItemArray[lItem]);
  1600. hr = WIA.WritePropertyLong(WIA_IPA_TYMED,TYMED_FILE);
  1601. if (S_OK == hr) {
  1602. // transfer to this file
  1603. hr = TransferToFile(szFileName,pIWiaItemArray[lItem]);
  1604. if ((hr == S_OK)||(WIA_STATUS_END_OF_MEDIA == hr)) {
  1605. GUID guidFormat;
  1606. memset(&guidFormat,0,sizeof(guidFormat));
  1607. hr = WIA.ReadPropertyGUID(WIA_IPA_FORMAT,&guidFormat);
  1608. if (S_OK == hr) {
  1609. RenameTempDataTransferFilesAndLaunchViewer(szFileName,guidFormat,TYMED_FILE);
  1610. } else {
  1611. ErrorMessageBox(IDS_WIATESTERROR_READINGFORMAT,hr);
  1612. }
  1613. } else if (FAILED(hr)) {
  1614. ErrorMessageBox(IDS_WIATESTERROR_ACQUISITION,hr);
  1615. }
  1616. } else {
  1617. ErrorMessageBox(IDS_WIATESTERROR_WRITINGTYMED,hr);
  1618. }
  1619. // release item after acquisition
  1620. pIWiaItemArray[lItem]->Release();
  1621. }
  1622. }
  1623. }
  1624. }
  1625. void CWiatestView::OnEditDebugout()
  1626. {
  1627. if(m_bOutputToDebuggerON){
  1628. m_bOutputToDebuggerON = FALSE;
  1629. DBG_SET_FLAGS(COREDBG_ERRORS);
  1630. } else {
  1631. m_bOutputToDebuggerON = TRUE;
  1632. DBG_SET_FLAGS(COREDBG_ERRORS | COREDBG_WARNINGS | COREDBG_TRACES);
  1633. }
  1634. }
  1635. void CWiatestView::OnUpdateEditDebugout(CCmdUI* pCmdUI)
  1636. {
  1637. pCmdUI->SetCheck(m_bOutputToDebuggerON);
  1638. }
  1639. void CWiatestView::RenameTempDataTransferFilesAndLaunchViewer(TCHAR *szFileName, GUID guidFormat, LONG lTymed)
  1640. {
  1641. TCHAR *pszFileExt = NULL;
  1642. TCHAR szOriginalFileName[MAX_PATH];
  1643. TCHAR szTempPath[MAX_PATH];
  1644. memset(szTempPath,0,sizeof(szTempPath));
  1645. memset(szOriginalFileName,0,sizeof(szOriginalFileName));
  1646. // copy original filename
  1647. lstrcpy(szOriginalFileName,szFileName);
  1648. // get temp launch path
  1649. GetTempPath(sizeof(szTempPath),szTempPath);
  1650. BOOL bKnownFormat = TRUE;
  1651. switch(lTymed){
  1652. case TYMED_CALLBACK:
  1653. case TYMED_MULTIPAGE_CALLBACK:
  1654. pszFileExt = TSTRSTR(szFileName,TEXT("mem"));
  1655. break;
  1656. case TYMED_FILE:
  1657. case TYMED_MULTIPAGE_FILE:
  1658. pszFileExt = TSTRSTR(szFileName,TEXT("fil"));
  1659. break;
  1660. default:
  1661. break;
  1662. }
  1663. if(lstrlen(szFileName) > 0){
  1664. if(pszFileExt){
  1665. // rename to known image formats
  1666. if(guidFormat == WiaImgFmt_UNDEFINED)
  1667. lstrcpy(pszFileExt,TEXT("bmp"));
  1668. else if(guidFormat == WiaImgFmt_MEMORYBMP)
  1669. lstrcpy(pszFileExt,TEXT("bmp"));
  1670. else if(guidFormat == WiaImgFmt_BMP)
  1671. lstrcpy(pszFileExt,TEXT("bmp"));
  1672. else if(guidFormat == WiaImgFmt_EMF)
  1673. lstrcpy(pszFileExt,TEXT("emf"));
  1674. else if(guidFormat == WiaImgFmt_WMF)
  1675. lstrcpy(pszFileExt,TEXT("wmf"));
  1676. else if(guidFormat == WiaImgFmt_JPEG)
  1677. lstrcpy(pszFileExt,TEXT("jpg"));
  1678. else if(guidFormat == WiaImgFmt_PNG)
  1679. lstrcpy(pszFileExt,TEXT("png"));
  1680. else if(guidFormat == WiaImgFmt_GIF)
  1681. lstrcpy(pszFileExt,TEXT("gif"));
  1682. else if(guidFormat == WiaImgFmt_TIFF)
  1683. lstrcpy(pszFileExt,TEXT("tif"));
  1684. else if(guidFormat == WiaImgFmt_EXIF)
  1685. lstrcpy(pszFileExt,TEXT("jpg"));
  1686. else if(guidFormat == WiaImgFmt_PHOTOCD)
  1687. lstrcpy(pszFileExt,TEXT("pcd"));
  1688. else if(guidFormat == WiaImgFmt_FLASHPIX)
  1689. lstrcpy(pszFileExt,TEXT("fpx"));
  1690. else {
  1691. TCHAR szValue[MAX_PATH];
  1692. memset(szValue,0,sizeof(szValue));
  1693. UCHAR *pwszUUID = NULL;
  1694. UuidToString(&guidFormat,&pwszUUID);
  1695. TSPRINTF(szValue,TEXT("%s"),pwszUUID);
  1696. // (TEXT("(Unknown Image type) GUID: %s"),pwszUUID);
  1697. // free allocated string
  1698. RpcStringFree(&pwszUUID);
  1699. bKnownFormat = FALSE;
  1700. }
  1701. }
  1702. }
  1703. if(bKnownFormat){
  1704. // delete any duplicates
  1705. DeleteFile(szFileName);
  1706. // rename file
  1707. MoveFile(szOriginalFileName,szFileName);
  1708. HINSTANCE hInst = NULL;
  1709. hInst = ShellExecute(m_hWnd,NULL,szFileName,NULL,szTempPath,SW_SHOW);
  1710. } else {
  1711. ErrorMessageBox(IDS_WIATESTERROR_UNKNOWN_IMAGEFORMAT);
  1712. }
  1713. }
  1714. void CWiatestView::DisplayMissingThumbnail()
  1715. {
  1716. //m_hThumbNailBitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_THUMBNAIL_MISSING_BITMAP));
  1717. //if(m_hThumbNailBitmap){
  1718. // display thumbnail(deleting any old one)
  1719. HBITMAP hPreviousBitmap = NULL;
  1720. //hPreviousBitmap = m_ThumbnailPreviewWindow.SetBitmap(m_hThumbNailBitmap);
  1721. hPreviousBitmap = m_ThumbnailPreviewWindow.GetBitmap();
  1722. if(hPreviousBitmap){
  1723. DeleteObject(hPreviousBitmap);
  1724. hPreviousBitmap = NULL;
  1725. }
  1726. m_ThumbnailPreviewWindow.Invalidate();
  1727. Invalidate();
  1728. //}
  1729. }
  1730. void CWiatestView::DisplayThumbnail(IWiaItem *pIWiaItem)
  1731. {
  1732. if(GET_STIDEVICE_TYPE(m_lDeviceType) == StiDeviceTypeDigitalCamera){
  1733. HRESULT hr = S_OK;
  1734. BYTE *pThumbNail = NULL;
  1735. CWiahelper WIA;
  1736. WIA.SetIWiaItem(pIWiaItem);
  1737. long lThumbNailHeight = 0;
  1738. long lThumbNailWidth = 0;
  1739. long lThumbNailSize = 0;
  1740. //
  1741. // read thumbnail height
  1742. //
  1743. hr = WIA.ReadPropertyLong(WIA_IPC_THUMB_HEIGHT,&lThumbNailHeight);
  1744. if(hr != S_OK){
  1745. if(FAILED(hr)){
  1746. ErrorMessageBox(IDS_WIATESTERROR_THUMBNAILHEIGHT,hr);
  1747. }
  1748. DisplayMissingThumbnail();
  1749. return;
  1750. }
  1751. //
  1752. // read thumbnail width
  1753. //
  1754. hr = WIA.ReadPropertyLong(WIA_IPC_THUMB_WIDTH,&lThumbNailWidth);
  1755. if(hr != S_OK){
  1756. if(FAILED(hr)){
  1757. ErrorMessageBox(IDS_WIATESTERROR_THUMBNAILWIDTH,hr);
  1758. }
  1759. DisplayMissingThumbnail();
  1760. return;
  1761. }
  1762. //
  1763. // read thumbnail data
  1764. //
  1765. LONG lDataSize = 0;
  1766. BYTE *pData = NULL;
  1767. hr = WIA.ReadPropertyData(WIA_IPC_THUMBNAIL,&pData,&lDataSize);
  1768. if (hr == S_OK) {
  1769. lThumbNailSize = lThumbNailWidth * lThumbNailHeight * 3;
  1770. if (lThumbNailSize != lDataSize) {
  1771. TCHAR szErrorResourceText[MAX_PATH];
  1772. memset(szErrorResourceText,0,sizeof(szErrorResourceText));
  1773. TCHAR szErrorText[MAX_PATH];
  1774. memset(szErrorText,0,sizeof(szErrorText));
  1775. RC2TSTR(IDS_WIATESTERROR_PROCESSING_THUMBNAILDATA,szErrorResourceText,sizeof(szErrorResourceText));
  1776. TSPRINTF(szErrorText,szErrorResourceText,lThumbNailSize,lDataSize);
  1777. ErrorMessageBox(szErrorText);
  1778. // free temp memory
  1779. if(pData){
  1780. GlobalFree(pData);
  1781. pData = NULL;
  1782. }
  1783. DisplayMissingThumbnail();
  1784. return;
  1785. }
  1786. BITMAPINFO bmi;
  1787. memset(&bmi,0,sizeof(bmi));
  1788. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1789. bmi.bmiHeader.biWidth = lThumbNailWidth;
  1790. bmi.bmiHeader.biHeight = lThumbNailHeight;
  1791. bmi.bmiHeader.biPlanes = 1;
  1792. bmi.bmiHeader.biBitCount = 24;
  1793. bmi.bmiHeader.biCompression = BI_RGB;
  1794. bmi.bmiHeader.biSizeImage = 0;
  1795. bmi.bmiHeader.biXPelsPerMeter = 0;
  1796. bmi.bmiHeader.biYPelsPerMeter = 0;
  1797. bmi.bmiHeader.biClrUsed = 0;
  1798. bmi.bmiHeader.biClrImportant = 0;
  1799. PBYTE pThumbNailData = NULL;
  1800. HDC hdc = ::GetDC(NULL);
  1801. if(hdc){
  1802. HDC hdcm = CreateCompatibleDC(hdc);
  1803. }
  1804. m_hThumbNailBitmap = CreateDIBSection(hdc,&bmi,DIB_RGB_COLORS,(void **)&pThumbNailData,NULL,0);
  1805. if(m_hThumbNailBitmap){
  1806. memcpy(pThumbNailData,pData,lDataSize);
  1807. }
  1808. // free temp memory
  1809. if(pData){
  1810. GlobalFree(pData);
  1811. pData = NULL;
  1812. }
  1813. // display thumbnail(deleting any old one)
  1814. HBITMAP hPreviousBitmap = NULL;
  1815. hPreviousBitmap = m_ThumbnailPreviewWindow.SetBitmap(m_hThumbNailBitmap);
  1816. if(hPreviousBitmap){
  1817. DeleteObject(hPreviousBitmap);
  1818. hPreviousBitmap = NULL;
  1819. }
  1820. m_ThumbnailPreviewWindow.Invalidate();
  1821. } else if(hr != S_OK){
  1822. if(FAILED(hr)){
  1823. ErrorMessageBox(IDS_WIATESTERROR_THUMBNAILDATA,hr);
  1824. }
  1825. DisplayMissingThumbnail();
  1826. return;
  1827. }
  1828. }
  1829. }
  1830. void CWiatestView::AdjustViewForDeviceType()
  1831. {
  1832. // get associated document
  1833. CWiatestDoc* pDocument = NULL;
  1834. pDocument = (CWiatestDoc*)m_pDocument;
  1835. if(pDocument){
  1836. m_lDeviceType = 0;
  1837. CWiahelper WIA;
  1838. HRESULT hr = S_OK;
  1839. WIA.SetIWiaItem(pDocument->m_pIRootItem);
  1840. hr = WIA.ReadPropertyLong(WIA_DIP_DEV_TYPE,&m_lDeviceType);
  1841. if(S_OK == hr){
  1842. if(GET_STIDEVICE_TYPE(m_lDeviceType) == StiDeviceTypeScanner){
  1843. // disable thumbnail preview window
  1844. m_ThumbnailPreviewWindow.ShowWindow(SW_HIDE);
  1845. LONG lDocHandlingSelect = 0;
  1846. hr = WIA.ReadPropertyLong(WIA_DPS_DOCUMENT_HANDLING_SELECT,&lDocHandlingSelect);
  1847. if(S_OK == hr){
  1848. // enable Document Acquisition settings menu option, and toolbar
  1849. m_bHasDocumentFeeder = TRUE;
  1850. }
  1851. }
  1852. } else {
  1853. // error?
  1854. }
  1855. }
  1856. }
  1857. void CWiatestView::RegisterForEvents()
  1858. {
  1859. HRESULT hr = S_OK;
  1860. IWiaDevMgr *pIWiaDevMgr = NULL;
  1861. hr = CoCreateInstance(CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr,(void**)&pIWiaDevMgr);
  1862. if(FAILED(hr)){
  1863. // creation of device manager failed, so we can not continue
  1864. ErrorMessageBox(IDS_WIATESTERROR_COCREATEWIADEVMGR,hr);
  1865. return;
  1866. }
  1867. CWiatestDoc* pDocument = NULL;
  1868. pDocument = (CWiatestDoc*)m_pDocument;
  1869. if (pDocument) {
  1870. // read device ID
  1871. CWiahelper WIA;
  1872. WIA.SetIWiaItem(pDocument->m_pIRootItem);
  1873. BSTR bstrDeviceID = NULL;
  1874. hr = WIA.ReadPropertyBSTR(WIA_DIP_DEV_ID,&bstrDeviceID);
  1875. if (FAILED(hr)) {
  1876. ErrorMessageBox(IDS_WIATESTERROR_DEVICEID,hr);
  1877. return;
  1878. }
  1879. WIA_DEV_CAP DevCap;
  1880. IEnumWIA_DEV_CAPS* pIEnumWiaDevCaps = NULL;
  1881. // enumerate all device events supported
  1882. hr = pDocument->m_pIRootItem->EnumDeviceCapabilities(WIA_DEVICE_EVENTS,&pIEnumWiaDevCaps);
  1883. if (S_OK == hr) {
  1884. LONG lEventIndex = 0;
  1885. IWiaEventCallback* pIWiaEventCallback = NULL;
  1886. hr = m_WiaEventCallback.QueryInterface(IID_IWiaEventCallback,(void **)&pIWiaEventCallback);
  1887. if (SUCCEEDED(hr)) {
  1888. do {
  1889. memset(&DevCap,0,sizeof(DevCap));
  1890. hr = pIEnumWiaDevCaps->Next(1,&DevCap,NULL);
  1891. if (S_OK == hr) {
  1892. // DevCap.ulFlags;
  1893. // DevCap.bstrIcon;
  1894. // DevCap.bstrCommanline;
  1895. // DevCap.guid;
  1896. hr = pIWiaDevMgr->RegisterEventCallbackInterface(0,
  1897. bstrDeviceID,
  1898. &DevCap.guid,
  1899. pIWiaEventCallback,
  1900. &m_WiaEventCallback.m_pIUnkRelease[lEventIndex]);
  1901. if (FAILED(hr)) {
  1902. ErrorMessageBox(IDS_WIATESTERROR_REGISTER_EVENT_CALLBACK,hr);
  1903. } else {
  1904. // increment index
  1905. lEventIndex++;
  1906. }
  1907. // free allocated strings
  1908. if (DevCap.bstrName) {
  1909. SysFreeString(DevCap.bstrName);
  1910. }
  1911. if (DevCap.bstrDescription) {
  1912. SysFreeString(DevCap.bstrDescription);
  1913. }
  1914. }
  1915. }while (hr == S_OK);
  1916. }
  1917. pIEnumWiaDevCaps->Release();
  1918. pIEnumWiaDevCaps = NULL;
  1919. }
  1920. }
  1921. pIWiaDevMgr->Release();
  1922. pIWiaDevMgr = NULL;
  1923. //CWnd* pParent = GetParent();
  1924. m_WiaEventCallback.SetViewWindowHandle(m_hWnd);
  1925. }
  1926. LRESULT CWiatestView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  1927. {
  1928. BOOL bProcessMessage = FALSE;
  1929. // is it one of the user defined messages??
  1930. switch (message) {
  1931. case WM_DEVICE_DISCONNECTED:
  1932. case WM_DEVICE_CONNECTED:
  1933. case WM_ITEM_DELETED:
  1934. case WM_ITEM_CREATED:
  1935. case WM_TREE_UPDATED:
  1936. case WM_STORAGE_CREATED:
  1937. case WM_STORAGE_DELETED:
  1938. bProcessMessage = TRUE;
  1939. break;
  1940. default:
  1941. break;
  1942. }
  1943. // if it is process it...
  1944. if (bProcessMessage) {
  1945. HRESULT hr = S_OK;
  1946. CWnd *pParent = GetParent();
  1947. if (pParent) {
  1948. CWiatestDoc* pDocument = NULL;
  1949. pDocument = (CWiatestDoc*)m_pDocument;
  1950. if (pDocument) {
  1951. switch (message) {
  1952. case WM_DEVICE_DISCONNECTED:
  1953. return pParent->PostMessage(WM_CLOSE,0,0);
  1954. break;
  1955. case WM_DEVICE_CONNECTED:
  1956. break;
  1957. case WM_ITEM_DELETED:
  1958. case WM_ITEM_CREATED:
  1959. case WM_TREE_UPDATED:
  1960. case WM_STORAGE_CREATED:
  1961. case WM_STORAGE_DELETED:
  1962. // refresh the item tree
  1963. AddWiaItemsToTreeControl(TVI_ROOT,pDocument->m_pIRootItem);
  1964. // refresh the properties
  1965. AddWiaItemPropertiesToListControl(pDocument->m_pIRootItem);
  1966. break;
  1967. default:
  1968. break;
  1969. }
  1970. }
  1971. }
  1972. }
  1973. // do default processing
  1974. return CFormView::WindowProc(message, wParam, lParam);
  1975. }
  1976. void CWiatestView::OnShowWindow(BOOL bShow, UINT nStatus)
  1977. {
  1978. CFormView::OnShowWindow(bShow, nStatus);
  1979. }
  1980. void CWiatestView::OnDocumentAcquisitionSettings()
  1981. {
  1982. CWiatestDoc* pDocument = NULL;
  1983. pDocument = (CWiatestDoc*)m_pDocument;
  1984. if (pDocument) {
  1985. CWiaDocAcqSettings DocumentAcquisitionSettingsDlg(IDS_WIATEST_DOCUMENT_SETTINGS_TITLE, pDocument->m_pIRootItem);
  1986. if (DocumentAcquisitionSettingsDlg.DoModal() != IDCANCEL) {
  1987. // refresh the item tree
  1988. AddWiaItemsToTreeControl(TVI_ROOT,pDocument->m_pIRootItem);
  1989. // refresh the properties
  1990. AddWiaItemPropertiesToListControl(pDocument->m_pIRootItem);
  1991. }
  1992. }
  1993. }
  1994. void CWiatestView::OnUpdateDocumentAcquisitionSettings(CCmdUI* pCmdUI)
  1995. {
  1996. pCmdUI->Enable(m_bHasDocumentFeeder);
  1997. }
  1998. void CWiatestView::OnSelchangeSupportedTymedAndFormatListbox()
  1999. {
  2000. CWiatestDoc* pDocument = NULL;
  2001. pDocument = (CWiatestDoc*)m_pDocument;
  2002. if(pDocument){
  2003. TCHAR szTymedAndFormat[MAX_PATH];
  2004. memset(szTymedAndFormat,0,sizeof(szTymedAndFormat));
  2005. INT iCurrentSelection = 0;
  2006. iCurrentSelection = m_SupportedTymedAndFormatsListBox.GetCurSel();
  2007. if(iCurrentSelection != -1){
  2008. m_SupportedTymedAndFormatsListBox.GetText(iCurrentSelection,szTymedAndFormat);
  2009. // find current TYMED selection (located in selected string)
  2010. LONG lTymed = TYMED_CALLBACK;
  2011. if(TSTRSTR(szTymedAndFormat,TEXT("TYMED_CALLBACK")) != NULL){
  2012. lTymed = TYMED_CALLBACK;
  2013. }
  2014. if(TSTRSTR(szTymedAndFormat,TEXT("TYMED_FILE")) != NULL){
  2015. lTymed = TYMED_FILE;
  2016. }
  2017. if(TSTRSTR(szTymedAndFormat,TEXT("TYMED_MULTIPAGE_CALLBACK")) != NULL){
  2018. lTymed = TYMED_MULTIPAGE_CALLBACK;
  2019. }
  2020. if(TSTRSTR(szTymedAndFormat,TEXT("TYMED_MULTIPAGE_FILE")) != NULL){
  2021. lTymed = TYMED_MULTIPAGE_FILE;
  2022. }
  2023. HRESULT hr = S_OK;
  2024. CWiahelper WIA;
  2025. WIA.SetIWiaItem(pDocument->m_pICurrentItem);
  2026. // write TYMED to device
  2027. hr = WIA.WritePropertyLong(WIA_IPA_TYMED,lTymed);
  2028. if (FAILED(hr)){
  2029. ErrorMessageBox(IDS_WIATESTERROR_WRITINGTYMED,hr);
  2030. return;
  2031. }
  2032. // find current format selection
  2033. TCHAR *pszGUID = NULL;
  2034. // trim off trailing ')' on guid string
  2035. LONG lLen = 0;
  2036. lLen = lstrlen(szTymedAndFormat);
  2037. szTymedAndFormat[(lLen * sizeof(TCHAR)) - sizeof(TCHAR)] = 0;
  2038. pszGUID = TSTRSTR(szTymedAndFormat,TEXT("("));
  2039. if(pszGUID){
  2040. pszGUID+=sizeof(TCHAR);
  2041. // we are on the GUID
  2042. GUID guidFormat = GUID_NULL;
  2043. memset(&guidFormat,0,sizeof(guidFormat));
  2044. #ifndef UNICODE
  2045. UuidFromString((UCHAR*)pszGUID,&guidFormat);
  2046. #else
  2047. WideCharToMultiByte(CP_ACP, 0,pszGUID,-1,szbuffer,MAX_PATH,NULL,NULL);
  2048. UuidFromString((UCHAR*)szbuffer,&guidFormat);
  2049. #endif
  2050. if(guidFormat != GUID_NULL){
  2051. hr = WIA.WritePropertyGUID(WIA_IPA_FORMAT,guidFormat);
  2052. if(SUCCEEDED(hr)){
  2053. AddWiaItemPropertiesToListControl(pDocument->m_pICurrentItem);
  2054. } else {
  2055. ErrorMessageBox(IDS_WIATESTERROR_WRITINGFORMAT,hr);
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. void CWiatestView::OnThumbnailPreview()
  2063. {
  2064. }