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.

275 lines
6.7 KiB

  1. #include <windows.h>
  2. #include <atlbase.h>
  3. #include "resource.h"
  4. #include "wia.h"
  5. #include "classes.h"
  6. #include "commctrl.h"
  7. extern CComPtr<IWiaDevMgr> g_pDevMgr;
  8. LARGE_INTEGER li1;
  9. LARGE_INTEGER li2;
  10. LARGE_INTEGER li3;
  11. LARGE_INTEGER liDiff;
  12. struct DRAWINFO
  13. {
  14. HBITMAP hbmp;
  15. LPVOID pBitmap;
  16. INT iWidth;
  17. INT iHeight;
  18. };
  19. #define GETDIFF(x,y) (liDiff.QuadPart = (x).QuadPart -(y).QuadPart)
  20. class CThumbsDlg
  21. {
  22. public:
  23. CThumbsDlg (CTest *pTest, BSTR strDeviceId);
  24. VOID ShowDlg ();
  25. private:
  26. INT m_iWidth;
  27. INT m_iHeight;
  28. HWND m_hwnd;
  29. HIMAGELIST m_himl;
  30. CTest *m_pTest;
  31. CComPtr<IWiaItem> m_pDevice;
  32. BSTR m_strDeviceId;
  33. VOID TimeEnumThumbnails ();
  34. static INT_PTR CALLBACK ShowThumbsDlgProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
  35. INT_PTR RealDlgProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
  36. VOID RenderThumbnail ();
  37. };
  38. VOID
  39. GetThumbSize (IWiaItem *pItem, INT *piWidth, INT *piHeight)
  40. {
  41. CComQIPtr<IWiaPropertyStorage, &IID_IWiaPropertyStorage> pstg(pItem);
  42. PROPVARIANT pv[2];
  43. PROPSPEC ps[2];
  44. ps[0].ulKind = ps[1].ulKind = PRSPEC_PROPID;
  45. ps[0].propid = WIA_DPC_THUMB_WIDTH;
  46. ps[1].propid = WIA_DPC_THUMB_HEIGHT;
  47. if (SUCCEEDED( pstg->ReadMultiple (2, ps, pv)))
  48. {
  49. *piWidth = pv[0].ulVal;
  50. *piHeight = pv[1].ulVal;
  51. }
  52. else
  53. {
  54. *piWidth = 0;
  55. *piHeight = 0;
  56. }
  57. FreePropVariantArray (2, pv);
  58. }
  59. HRESULT
  60. GetNameAndThumbnail (IWiaItem *pItem, LPTSTR szName, DRAWINFO *pInfo)
  61. {
  62. CComQIPtr<IWiaPropertyStorage, &IID_IWiaPropertyStorage> pstg(pItem);
  63. PROPVARIANT pv[4];
  64. PROPSPEC ps[4];
  65. HRESULT hr;
  66. BITMAPINFO bmi;
  67. HWND hwnd;
  68. HDC hdc;
  69. ps[0].ulKind = ps[1].ulKind = ps[2].ulKind = ps[3].ulKind = PRSPEC_PROPID;
  70. ps[0].propid = WIA_IPA_ITEM_NAME;
  71. ps[1].propid = WIA_IPC_THUMBNAIL;
  72. ps[2].propid = WIA_IPC_THUMB_WIDTH;
  73. ps[3].propid = WIA_IPC_THUMB_HEIGHT;
  74. hr = pstg->ReadMultiple (4, ps, pv);
  75. if (SUCCEEDED(hr))
  76. {
  77. #ifdef UNICODE
  78. lstrcpy (szName, pv[0].pwszVal);
  79. #else
  80. WideCharToMultiByte (CP_ACP, 0, pv[0].pwszVal, -1, szName, MAX_PATH,
  81. NULL,NULL);
  82. #endif
  83. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  84. bmi.bmiHeader.biWidth = pv[2].ulVal;
  85. bmi.bmiHeader.biHeight = pv[3].ulVal;
  86. bmi.bmiHeader.biPlanes = 1;
  87. bmi.bmiHeader.biBitCount = 24;
  88. bmi.bmiHeader.biCompression = BI_RGB;
  89. bmi.bmiHeader.biSizeImage = 0;
  90. bmi.bmiHeader.biXPelsPerMeter = 0;
  91. bmi.bmiHeader.biYPelsPerMeter = 0;
  92. bmi.bmiHeader.biClrUsed = 0;
  93. bmi.bmiHeader.biClrImportant = 0;
  94. hwnd = GetDesktopWindow();
  95. hdc = GetDC( hwnd );
  96. pInfo->hbmp = CreateDIBSection( hdc, &bmi, DIB_RGB_COLORS, &pInfo->pBitmap, NULL, 0 );
  97. pInfo->iHeight = bmi.bmiHeader.biHeight;
  98. pInfo->iWidth = bmi.bmiHeader.biWidth;
  99. //
  100. // Transfer thumbnail bits to bitmap bits
  101. //
  102. CopyMemory( pInfo->pBitmap, pv[1].caub.pElems, pv[1].caub.cElems );
  103. FreePropVariantArray (4, pv);
  104. ReleaseDC (hwnd, hdc);
  105. }
  106. return hr;
  107. }
  108. VOID
  109. CThumbsDlg::TimeEnumThumbnails ()
  110. {
  111. CComPtr<IEnumWiaItem> pEnum;
  112. HWND hList = GetDlgItem (m_hwnd, IDC_THUMBS);
  113. QueryPerformanceCounter (&li3);
  114. if (SUCCEEDED(m_pDevice->EnumChildItems (&pEnum)))
  115. {
  116. ULONG ul;
  117. CComPtr<IWiaItem> pItem;
  118. LVITEM lvi;
  119. TCHAR szName[MAX_PATH];
  120. HBITMAP hbmp;
  121. DRAWINFO *pInfo;
  122. QueryPerformanceCounter (&li2);
  123. GETDIFF(li2, li3);
  124. m_pTest->LogTime(TEXT("IWiaItem::EnumChildItems"), liDiff);
  125. m_pTest->LogAPI(TEXT("IWiaItem::EnumChildItems"), NOERROR);
  126. ZeroMemory (&lvi, sizeof(lvi));
  127. lvi.mask = LVIF_IMAGE | LVIF_TEXT;
  128. QueryPerformanceCounter (&li2);
  129. while (NOERROR == pEnum->Next (1, &pItem, &ul))
  130. {
  131. DRAWINFO Info;
  132. if (SUCCEEDED(GetNameAndThumbnail (pItem, szName, &Info)))
  133. {
  134. lvi.pszText = szName;
  135. lvi.iImage = ImageList_Add (m_himl, Info.hbmp, NULL);
  136. ListView_InsertItem (hList, &lvi);
  137. DeleteObject (Info.hbmp);
  138. }
  139. pItem = NULL;
  140. }
  141. ListView_SetIconSpacing (hList, m_iWidth+16, m_iHeight+32);
  142. ListView_SetImageList (hList, m_himl, LVSIL_NORMAL);
  143. QueryPerformanceCounter (&li3);
  144. GETDIFF (li3, li2);
  145. m_pTest->LogTime(TEXT("Add thumbnails to listview"), liDiff);
  146. }
  147. }
  148. INT_PTR CALLBACK
  149. CThumbsDlg::ShowThumbsDlgProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  150. {
  151. switch (msg)
  152. {
  153. case WM_INITDIALOG:
  154. SetWindowLongPtr (hwnd, DWLP_USER, lp);
  155. break;
  156. }
  157. CThumbsDlg *pThis = reinterpret_cast<CThumbsDlg*>(GetWindowLongPtr(hwnd, DWLP_USER));
  158. return pThis->RealDlgProc (hwnd, msg ,wp ,lp);
  159. }
  160. INT_PTR
  161. CThumbsDlg::RealDlgProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  162. {
  163. switch (msg)
  164. {
  165. case WM_INITDIALOG:
  166. m_hwnd = hwnd;
  167. PostMessage (hwnd, WM_USER+10, 0, 0);
  168. return TRUE;
  169. case WM_USER+10:
  170. TimeEnumThumbnails ();
  171. PostMessage (hwnd, WM_CLOSE, 0, 0);
  172. return TRUE;
  173. case WM_CLOSE:
  174. EndDialog (hwnd, 0);
  175. return TRUE;
  176. }
  177. return FALSE;
  178. }
  179. VOID
  180. CThumbsDlg::ShowDlg()
  181. {
  182. HRESULT hr;
  183. QueryPerformanceCounter (&li1);
  184. hr = g_pDevMgr->CreateDevice (m_strDeviceId, &m_pDevice);
  185. if (SUCCEEDED(hr))
  186. {
  187. QueryPerformanceCounter (&li2);
  188. GETDIFF (li2, li1);
  189. m_pTest->LogTime(TEXT("IWiaDevMgr::CreateDevice"), liDiff);
  190. }
  191. m_pTest->LogAPI (TEXT("IWiaDevMgr::CreateDevice"), hr);
  192. GetThumbSize (m_pDevice, &m_iWidth, &m_iHeight);
  193. m_himl = ImageList_Create (m_iWidth, m_iHeight, ILC_COLOR24, 10, 50);
  194. DialogBoxParam (GetModuleHandle (NULL),
  195. MAKEINTRESOURCE (IDD_SHOWTHUMBS),
  196. NULL,
  197. ShowThumbsDlgProc,
  198. reinterpret_cast<LPARAM>(this));
  199. QueryPerformanceCounter (&li2);
  200. GETDIFF (li2, li1);
  201. m_pTest->LogTime (TEXT("Complete enumeration of thumbnails"), liDiff);
  202. }
  203. CThumbsDlg::CThumbsDlg(CTest *pTest, BSTR strDeviceId)
  204. {
  205. m_pTest = pTest;
  206. m_strDeviceId = strDeviceId;
  207. }
  208. VOID
  209. CTest::TstShowThumbs(CTest *pThis, BSTR strDeviceId)
  210. {
  211. INITCOMMONCONTROLSEX ice;
  212. CThumbsDlg dlg(pThis, strDeviceId);
  213. ice.dwSize = sizeof(ice);
  214. ice.dwICC = ICC_LISTVIEW_CLASSES;
  215. InitCommonControlsEx (&ice);
  216. pThis->LogString(TEXT("-->Begin thumbnail enumeration test"));
  217. dlg.ShowDlg ();
  218. pThis->LogString(TEXT("<--End thumbnail enumeration test"));
  219. }