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.

1779 lines
74 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: MAIN.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/3/2000
  12. *
  13. * DESCRIPTION: Random unit testing program for various UI components
  14. *
  15. *******************************************************************************/
  16. #include <windows.h>
  17. #include <windowsx.h>
  18. #include <commctrl.h>
  19. #include <initguid.h>
  20. #include <atlbase.h>
  21. #include <objbase.h>
  22. #include <wia.h>
  23. #include <sti.h>
  24. #include <simstr.h>
  25. #include <shellext.h>
  26. #include <upnp.h>
  27. #include <simbstr.h>
  28. #include <simreg.h>
  29. #include <dumpprop.h>
  30. #include <simrect.h>
  31. #include "uicommon.h"
  32. #include "wiadebug.h"
  33. #include "resource.h"
  34. #include "simcrack.h"
  35. #include "wiadevdp.h"
  36. #include "isuppfmt.h"
  37. #include "itranhlp.h"
  38. #include "gphelper.h"
  39. #include "runwiz.h"
  40. #include "runnpwiz.h"
  41. #include "multistr.h"
  42. #include "mboxex.h"
  43. #define SELECT_DEVICE_TYPE StiDeviceTypeDefault
  44. HINSTANCE g_hInstance;
  45. #define PWM_DISPLAYNEWIMAGE (WM_USER+122)
  46. class CWiaDataCallbackBase : public IWiaDataCallback
  47. {
  48. private:
  49. LONG m_cRef;
  50. public:
  51. CWiaDataCallbackBase()
  52. : m_cRef(1)
  53. {
  54. }
  55. ~CWiaDataCallbackBase()
  56. {
  57. }
  58. STDMETHODIMP QueryInterface(const IID& iid, void** ppvObject)
  59. {
  60. if ((iid==IID_IUnknown) || (iid==IID_IWiaDataCallback))
  61. {
  62. *ppvObject = static_cast<LPVOID>(this);
  63. }
  64. else
  65. {
  66. *ppvObject = NULL;
  67. return(E_NOINTERFACE);
  68. }
  69. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  70. return(S_OK);
  71. }
  72. STDMETHODIMP_(ULONG) AddRef()
  73. {
  74. return(InterlockedIncrement(&m_cRef));
  75. }
  76. STDMETHODIMP_(ULONG) Release()
  77. {
  78. if (InterlockedDecrement(&m_cRef)==0)
  79. {
  80. delete this;
  81. return 0;
  82. }
  83. return(m_cRef);
  84. }
  85. STDMETHODIMP BandedDataCallback(
  86. LONG lReason,
  87. LONG lStatus,
  88. LONG lPercentComplete,
  89. LONG lOffset,
  90. LONG lLength,
  91. LONG lReserved,
  92. LONG lResLength,
  93. PBYTE pbBuffer)
  94. {
  95. if (lReason == IT_MSG_STATUS)
  96. {
  97. TCHAR szMessage[MAX_PATH];
  98. wsprintf( szMessage, TEXT("IT_MSG_STATUS: Percent Done (in client callback): %d\n"), lPercentComplete );
  99. OutputDebugString( szMessage );
  100. }
  101. else if (lReason == IT_MSG_DATA)
  102. {
  103. TCHAR szMessage[MAX_PATH];
  104. wsprintf( szMessage, TEXT("IT_MSG_DATA: Percent Done (in client callback): %d\n"), lPercentComplete );
  105. OutputDebugString( szMessage );
  106. }
  107. return S_OK;
  108. }
  109. static IWiaDataCallback *CreateInstance(void)
  110. {
  111. IWiaDataCallback *pWiaDataCallback = NULL;
  112. CWiaDataCallbackBase *pWiaDataCallbackBase = new CWiaDataCallbackBase;
  113. if (pWiaDataCallbackBase)
  114. {
  115. HRESULT hr = pWiaDataCallbackBase->QueryInterface( IID_IWiaDataCallback, (void**)&pWiaDataCallback );
  116. pWiaDataCallbackBase->Release();
  117. }
  118. return pWiaDataCallback;
  119. }
  120. };
  121. class CProgressDialogFlagsDialog
  122. {
  123. public:
  124. struct CData
  125. {
  126. LONG lFlags;
  127. };
  128. private:
  129. HWND m_hWnd;
  130. CData *m_pData;
  131. private:
  132. //
  133. // Not implemented
  134. //
  135. CProgressDialogFlagsDialog( const CProgressDialogFlagsDialog & );
  136. CProgressDialogFlagsDialog(void);
  137. CProgressDialogFlagsDialog &operator=( const CProgressDialogFlagsDialog & );
  138. private:
  139. //
  140. // Sole constructor
  141. //
  142. explicit CProgressDialogFlagsDialog( HWND hWnd )
  143. : m_hWnd(hWnd),
  144. m_pData(NULL)
  145. {
  146. }
  147. ~CProgressDialogFlagsDialog(void)
  148. {
  149. m_hWnd = NULL;
  150. }
  151. LRESULT OnInitDialog( WPARAM, LPARAM lParam )
  152. {
  153. m_pData = reinterpret_cast<CData*>(lParam);
  154. if (m_pData)
  155. {
  156. if ((m_pData->lFlags & WIA_PROGRESSDLG_NO_PROGRESS)==0)
  157. {
  158. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_PROGRESS, BM_SETCHECK, BST_CHECKED, 0 );
  159. }
  160. if ((m_pData->lFlags & WIA_PROGRESSDLG_NO_CANCEL)==0)
  161. {
  162. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CANCEL, BM_SETCHECK, BST_CHECKED, 0 );
  163. }
  164. if ((m_pData->lFlags & WIA_PROGRESSDLG_NO_ANIM)==0)
  165. {
  166. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_ANIM, BM_SETCHECK, BST_CHECKED, 0 );
  167. }
  168. if ((m_pData->lFlags & WIA_PROGRESSDLG_NO_TITLE)==0)
  169. {
  170. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_TITLE, BM_SETCHECK, BST_CHECKED, 0 );
  171. }
  172. if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_SCANNER_COMMUNICATE)
  173. {
  174. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_SCAN_CONNECT, BM_SETCHECK, BST_CHECKED, 0 );
  175. }
  176. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_CAMERA_COMMUNICATE)
  177. {
  178. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CAMERA_CONNECT, BM_SETCHECK, BST_CHECKED, 0 );
  179. }
  180. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_VIDEO_COMMUNICATE)
  181. {
  182. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_VIDEO_CONNECT, BM_SETCHECK, BST_CHECKED, 0 );
  183. }
  184. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_SCANNER_ACQUIRE)
  185. {
  186. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_SCAN_ACQUIRE, BM_SETCHECK, BST_CHECKED, 0 );
  187. }
  188. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_CAMERA_ACQUIRE)
  189. {
  190. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CAMERA_ACQUIRE, BM_SETCHECK, BST_CHECKED, 0 );
  191. }
  192. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_VIDEO_ACQUIRE)
  193. {
  194. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_VIDEO_ACQUIRE, BM_SETCHECK, BST_CHECKED, 0 );
  195. }
  196. else if (m_pData->lFlags & WIA_PROGRESSDLG_ANIM_DEFAULT_COMMUNICATE)
  197. {
  198. SendDlgItemMessage( m_hWnd, IDC_PROGDLG_DEFAULT_CONNECT, BM_SETCHECK, BST_CHECKED, 0 );
  199. }
  200. HandleAnimSettingsChange();
  201. }
  202. else
  203. {
  204. EndDialog( m_hWnd, IDCANCEL );
  205. }
  206. return 0;
  207. }
  208. void HandleAnimSettingsChange(void)
  209. {
  210. BOOL bEnable = (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_ANIM, BM_GETCHECK, 0, 0 ));
  211. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_SCAN_CONNECT ), bEnable );
  212. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_CAMERA_CONNECT ), bEnable );
  213. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_VIDEO_CONNECT ), bEnable );
  214. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_SCAN_ACQUIRE ), bEnable );
  215. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_CAMERA_ACQUIRE ), bEnable );
  216. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_VIDEO_ACQUIRE ), bEnable );
  217. EnableWindow( GetDlgItem( m_hWnd, IDC_PROGDLG_DEFAULT_CONNECT ), bEnable );
  218. }
  219. void OnAnimClicked( WPARAM, LPARAM )
  220. {
  221. HandleAnimSettingsChange();
  222. }
  223. void OnCancel( WPARAM, LPARAM )
  224. {
  225. EndDialog( m_hWnd, IDCANCEL );
  226. }
  227. void OnOK( WPARAM, LPARAM )
  228. {
  229. if (m_pData)
  230. {
  231. m_pData->lFlags = 0;
  232. if (BST_CHECKED != SendDlgItemMessage( m_hWnd, IDC_PROGDLG_PROGRESS, BM_GETCHECK, 0, 0 ))
  233. {
  234. m_pData->lFlags |= WIA_PROGRESSDLG_NO_PROGRESS;
  235. }
  236. if (BST_CHECKED != SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CANCEL, BM_GETCHECK, 0, 0 ))
  237. {
  238. m_pData->lFlags |= WIA_PROGRESSDLG_NO_CANCEL;
  239. }
  240. if (BST_CHECKED != SendDlgItemMessage( m_hWnd, IDC_PROGDLG_ANIM, BM_GETCHECK, 0, 0 ))
  241. {
  242. m_pData->lFlags |= WIA_PROGRESSDLG_NO_ANIM;
  243. }
  244. if (BST_CHECKED != SendDlgItemMessage( m_hWnd, IDC_PROGDLG_TITLE, BM_GETCHECK, 0, 0 ))
  245. {
  246. m_pData->lFlags |= WIA_PROGRESSDLG_NO_TITLE;
  247. }
  248. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_SCAN_CONNECT, BM_GETCHECK, 0, 0 ))
  249. {
  250. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_SCANNER_COMMUNICATE;
  251. }
  252. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CAMERA_CONNECT, BM_GETCHECK, 0, 0 ))
  253. {
  254. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_CAMERA_COMMUNICATE;
  255. }
  256. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_VIDEO_CONNECT, BM_GETCHECK, 0, 0 ))
  257. {
  258. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_VIDEO_COMMUNICATE;
  259. }
  260. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_SCAN_ACQUIRE, BM_GETCHECK, 0, 0 ))
  261. {
  262. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_SCANNER_ACQUIRE;
  263. }
  264. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_CAMERA_ACQUIRE, BM_GETCHECK, 0, 0 ))
  265. {
  266. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_CAMERA_ACQUIRE;
  267. }
  268. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_VIDEO_ACQUIRE, BM_GETCHECK, 0, 0 ))
  269. {
  270. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_VIDEO_ACQUIRE;
  271. }
  272. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_PROGDLG_DEFAULT_CONNECT, BM_GETCHECK, 0, 0 ))
  273. {
  274. m_pData->lFlags |= WIA_PROGRESSDLG_ANIM_DEFAULT_COMMUNICATE;
  275. }
  276. }
  277. EndDialog( m_hWnd, IDOK );
  278. }
  279. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  280. {
  281. SC_BEGIN_COMMAND_HANDLERS()
  282. {
  283. SC_HANDLE_COMMAND(IDCANCEL,OnCancel);
  284. SC_HANDLE_COMMAND(IDOK,OnOK);
  285. SC_HANDLE_COMMAND(IDC_PROGDLG_ANIM,OnAnimClicked);
  286. }
  287. SC_END_COMMAND_HANDLERS();
  288. }
  289. public:
  290. static INT_PTR DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  291. {
  292. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CProgressDialogFlagsDialog)
  293. {
  294. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  295. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  296. }
  297. SC_END_DIALOG_MESSAGE_HANDLERS();
  298. }
  299. };
  300. class CMessageBoxExFlagsDialog
  301. {
  302. public:
  303. struct CData
  304. {
  305. LONG lFlags;
  306. };
  307. private:
  308. HWND m_hWnd;
  309. CData *m_pData;
  310. private:
  311. //
  312. // Not implemented
  313. //
  314. CMessageBoxExFlagsDialog( const CMessageBoxExFlagsDialog & );
  315. CMessageBoxExFlagsDialog(void);
  316. CMessageBoxExFlagsDialog &operator=( const CMessageBoxExFlagsDialog & );
  317. private:
  318. //
  319. // Sole constructor
  320. //
  321. explicit CMessageBoxExFlagsDialog( HWND hWnd )
  322. : m_hWnd(hWnd),
  323. m_pData(NULL)
  324. {
  325. }
  326. ~CMessageBoxExFlagsDialog(void)
  327. {
  328. m_hWnd = NULL;
  329. }
  330. LRESULT OnInitDialog( WPARAM, LPARAM lParam )
  331. {
  332. m_pData = reinterpret_cast<CData*>(lParam);
  333. if (m_pData)
  334. {
  335. if ((m_pData->lFlags & CMessageBoxEx::MBEX_OKCANCEL) != 0)
  336. {
  337. SendDlgItemMessage( m_hWnd, IDC_MBEX_OKCANCEL, BM_SETCHECK, BST_CHECKED, 0 );
  338. }
  339. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_YESNO) != 0)
  340. {
  341. SendDlgItemMessage( m_hWnd, IDC_MBEX_YESNO, BM_SETCHECK, BST_CHECKED, 0 );
  342. }
  343. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_CANCELRETRYSKIPSKIPALL) != 0)
  344. {
  345. SendDlgItemMessage( m_hWnd, IDC_MBEX_CANCELRETRYSKIPSKIPALL, BM_SETCHECK, BST_CHECKED, 0 );
  346. }
  347. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_CANCELRETRYSKIPSKIPALL) != 0)
  348. {
  349. SendDlgItemMessage( m_hWnd, IDC_MBEX_YESYESTOALLNONOTOALL, BM_SETCHECK, BST_CHECKED, 0 );
  350. }
  351. else
  352. {
  353. SendDlgItemMessage( m_hWnd, IDC_MBEX_OK, BM_SETCHECK, BST_CHECKED, 0 );
  354. }
  355. if ((m_pData->lFlags & CMessageBoxEx::MBEX_DEFBUTTON2) != 0)
  356. {
  357. SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON2, BM_SETCHECK, BST_CHECKED, 0 );
  358. }
  359. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_DEFBUTTON3) != 0)
  360. {
  361. SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON3, BM_SETCHECK, BST_CHECKED, 0 );
  362. }
  363. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_DEFBUTTON4) != 0)
  364. {
  365. SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON4, BM_SETCHECK, BST_CHECKED, 0 );
  366. }
  367. else
  368. {
  369. SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON1, BM_SETCHECK, BST_CHECKED, 0 );
  370. }
  371. if ((m_pData->lFlags & CMessageBoxEx::MBEX_ICONERROR) != 0)
  372. {
  373. SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONERROR, BM_SETCHECK, BST_CHECKED, 0 );
  374. }
  375. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_ICONWARNING) != 0)
  376. {
  377. SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONWARNING, BM_SETCHECK, BST_CHECKED, 0 );
  378. }
  379. else if ((m_pData->lFlags & CMessageBoxEx::MBEX_ICONQUESTION) != 0)
  380. {
  381. SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONQUESTION, BM_SETCHECK, BST_CHECKED, 0 );
  382. }
  383. else
  384. {
  385. SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONINFORMATION, BM_SETCHECK, BST_CHECKED, 0 );
  386. }
  387. }
  388. else
  389. {
  390. EndDialog( m_hWnd, IDCANCEL );
  391. }
  392. return 0;
  393. }
  394. void OnCancel( WPARAM, LPARAM )
  395. {
  396. EndDialog( m_hWnd, IDCANCEL );
  397. }
  398. void OnOK( WPARAM, LPARAM )
  399. {
  400. if (m_pData)
  401. {
  402. m_pData->lFlags = 0;
  403. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_OKCANCEL, BM_GETCHECK, 0, 0 ))
  404. {
  405. m_pData->lFlags |= CMessageBoxEx::MBEX_OKCANCEL;
  406. }
  407. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_YESNO, BM_GETCHECK, 0, 0 ))
  408. {
  409. m_pData->lFlags |= CMessageBoxEx::MBEX_YESNO;
  410. }
  411. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_CANCELRETRYSKIPSKIPALL, BM_GETCHECK, 0, 0 ))
  412. {
  413. m_pData->lFlags |= CMessageBoxEx::MBEX_CANCELRETRYSKIPSKIPALL;
  414. }
  415. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_YESYESTOALLNONOTOALL, BM_GETCHECK, 0, 0 ))
  416. {
  417. m_pData->lFlags |= CMessageBoxEx::MBEX_YESYESTOALLNONOTOALL;
  418. }
  419. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_OK, BM_GETCHECK, 0, 0 ))
  420. {
  421. m_pData->lFlags |= CMessageBoxEx::MBEX_OK;
  422. }
  423. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON2, BM_GETCHECK, 0, 0 ))
  424. {
  425. m_pData->lFlags |= CMessageBoxEx::MBEX_DEFBUTTON2;
  426. }
  427. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON3, BM_GETCHECK, 0, 0 ))
  428. {
  429. m_pData->lFlags |= CMessageBoxEx::MBEX_DEFBUTTON3;
  430. }
  431. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON4, BM_GETCHECK, 0, 0 ))
  432. {
  433. m_pData->lFlags |= CMessageBoxEx::MBEX_DEFBUTTON4;
  434. }
  435. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_DEFBUTTON1, BM_GETCHECK, 0, 0 ))
  436. {
  437. m_pData->lFlags |= CMessageBoxEx::MBEX_DEFBUTTON1;
  438. }
  439. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONINFORMATION, BM_GETCHECK, 0, 0 ))
  440. {
  441. m_pData->lFlags |= CMessageBoxEx::MBEX_ICONINFORMATION;
  442. }
  443. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONWARNING, BM_GETCHECK, 0, 0 ))
  444. {
  445. m_pData->lFlags |= CMessageBoxEx::MBEX_ICONWARNING;
  446. }
  447. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONQUESTION, BM_GETCHECK, 0, 0 ))
  448. {
  449. m_pData->lFlags |= CMessageBoxEx::MBEX_ICONQUESTION;
  450. }
  451. if (BST_CHECKED == SendDlgItemMessage( m_hWnd, IDC_MBEX_ICONERROR, BM_GETCHECK, 0, 0 ))
  452. {
  453. m_pData->lFlags |= CMessageBoxEx::MBEX_ICONERROR;
  454. }
  455. }
  456. EndDialog( m_hWnd, IDOK );
  457. }
  458. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  459. {
  460. SC_BEGIN_COMMAND_HANDLERS()
  461. {
  462. SC_HANDLE_COMMAND(IDCANCEL,OnCancel);
  463. SC_HANDLE_COMMAND(IDOK,OnOK);
  464. }
  465. SC_END_COMMAND_HANDLERS();
  466. }
  467. public:
  468. static INT_PTR DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  469. {
  470. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CMessageBoxExFlagsDialog)
  471. {
  472. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  473. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  474. }
  475. SC_END_DIALOG_MESSAGE_HANDLERS();
  476. }
  477. };
  478. class CMiscUnitTestWindow : public IUPnPServiceCallback
  479. {
  480. private:
  481. HWND m_hWnd;
  482. LONG m_nProgressDialogFlags;
  483. LONG m_nMessageBoxExFlags;
  484. HBITMAP m_hOriginalBitmap;
  485. HBITMAP m_hTransformedBitmap;
  486. BYTE m_nThreshold;
  487. BYTE m_nContrast;
  488. BYTE m_nBrightness;
  489. CComPtr<IUPnPService> m_pUPnPService;
  490. private:
  491. CMiscUnitTestWindow(void);
  492. CMiscUnitTestWindow( const CMiscUnitTestWindow & );
  493. CMiscUnitTestWindow &operator=( const CMiscUnitTestWindow & );
  494. private:
  495. explicit CMiscUnitTestWindow( HWND hWnd )
  496. : m_hWnd(hWnd),
  497. m_nProgressDialogFlags(WIA_PROGRESSDLG_ANIM_SCANNER_COMMUNICATE),
  498. m_hOriginalBitmap(NULL),
  499. m_nMessageBoxExFlags(0),
  500. m_hTransformedBitmap(NULL),
  501. m_nThreshold(50),
  502. m_nContrast(50),
  503. m_nBrightness(50)
  504. {
  505. }
  506. ~CMiscUnitTestWindow(void)
  507. {
  508. if (m_hOriginalBitmap)
  509. {
  510. DeleteObject(m_hOriginalBitmap);
  511. m_hOriginalBitmap = NULL;
  512. }
  513. if (m_hTransformedBitmap)
  514. {
  515. DeleteObject(m_hTransformedBitmap);
  516. m_hTransformedBitmap = NULL;
  517. }
  518. }
  519. void DestroyBitmap( bool bRepaint=true )
  520. {
  521. if (m_hOriginalBitmap)
  522. {
  523. DeleteObject(m_hOriginalBitmap);
  524. m_hOriginalBitmap = NULL;
  525. }
  526. if (m_hTransformedBitmap)
  527. {
  528. DeleteObject(m_hTransformedBitmap);
  529. m_hTransformedBitmap = NULL;
  530. }
  531. if (bRepaint)
  532. {
  533. InvalidateRect( m_hWnd, NULL, TRUE );
  534. UpdateWindow( m_hWnd );
  535. }
  536. }
  537. LRESULT OnDestroy( WPARAM, LPARAM )
  538. {
  539. m_pUPnPService = NULL;
  540. PostQuitMessage(0);
  541. return(0);
  542. }
  543. LRESULT OnCreate( WPARAM, LPARAM )
  544. {
  545. SendMessage( m_hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDI_TESTACQD), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR )));
  546. SendMessage( m_hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDI_TESTACQD), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR )));
  547. m_hOriginalBitmap = reinterpret_cast<HBITMAP>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDB_TESTIMAGE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ));
  548. HWND hWnd = CreateWindow( WC_LINK, TEXT("<a>This is a link that will only show up if this application is fusionized</a>"), WS_CHILD|WS_VISIBLE, 0, 0, 200, 20, m_hWnd, reinterpret_cast<HMENU>(1), g_hInstance, NULL );
  549. if (!hWnd)
  550. {
  551. WIA_PRINTHRESULT((HRESULT_FROM_WIN32(GetLastError()),TEXT("CreateWindow returned")));
  552. }
  553. return(0);
  554. }
  555. void OnFileExit( WPARAM, LPARAM )
  556. {
  557. DestroyWindow(m_hWnd);
  558. }
  559. void OnProgressTestProgress( WPARAM, LPARAM )
  560. {
  561. WIA_PUSH_FUNCTION((TEXT("OnProgressTestProgress")));
  562. CComPtr<IWiaProgressDialog> pWiaProgressDialog;
  563. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaProgressDialog, (void**)&pWiaProgressDialog );
  564. if (SUCCEEDED(hr))
  565. {
  566. pWiaProgressDialog->Create( m_hWnd, m_nProgressDialogFlags );
  567. pWiaProgressDialog->SetTitle( L"This is the title" );
  568. pWiaProgressDialog->Show();
  569. for (int i=0;i<100;i++)
  570. {
  571. pWiaProgressDialog->SetMessage( CSimpleStringWide().Format( L"%d percent complete!", i ).String() );
  572. pWiaProgressDialog->SetPercentComplete(i);
  573. BOOL bCancelled = FALSE;
  574. pWiaProgressDialog->Cancelled(&bCancelled);
  575. if (bCancelled)
  576. {
  577. Sleep(1000);
  578. break;
  579. }
  580. Sleep(100);
  581. }
  582. pWiaProgressDialog->Destroy();
  583. }
  584. WIA_PRINTHRESULT((hr,TEXT("OnProgressTestProgress returning")));
  585. }
  586. void OnProgressSetFlags( WPARAM, LPARAM )
  587. {
  588. CProgressDialogFlagsDialog::CData Data;
  589. Data.lFlags = m_nProgressDialogFlags;
  590. if (IDOK == DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_PROGRESS_DIALOG_SETTINGS), m_hWnd, CProgressDialogFlagsDialog::DialogProc, reinterpret_cast<LPARAM>(&Data)))
  591. {
  592. m_nProgressDialogFlags = Data.lFlags;
  593. }
  594. }
  595. void OnMBoxSetFlags( WPARAM, LPARAM )
  596. {
  597. CMessageBoxExFlagsDialog::CData Data;
  598. Data.lFlags = m_nMessageBoxExFlags;
  599. if (IDOK == DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_MBOXFLAGS), m_hWnd, CMessageBoxExFlagsDialog::DialogProc, reinterpret_cast<LPARAM>(&Data)))
  600. {
  601. m_nMessageBoxExFlags = Data.lFlags;
  602. }
  603. }
  604. void OnWiaDeviceDlg( WPARAM, LPARAM )
  605. {
  606. CComPtr<IWiaDevMgr> pIWiaDevMgr;
  607. HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void**)&pIWiaDevMgr );
  608. if (SUCCEEDED(hr))
  609. {
  610. CComPtr<IWiaItem> pWiaItemRoot;
  611. hr = pIWiaDevMgr->SelectDeviceDlg( m_hWnd, SELECT_DEVICE_TYPE, 0, NULL, &pWiaItemRoot );
  612. if (SUCCEEDED(hr) && (S_FALSE != hr))
  613. {
  614. LONG nItemCount;
  615. IWiaItem **ppIWiaItems;
  616. hr = pWiaItemRoot->DeviceDlg( m_hWnd, 0, WIA_INTENT_MAXIMIZE_QUALITY, &nItemCount, &ppIWiaItems );
  617. if (SUCCEEDED(hr) && hr != S_FALSE)
  618. {
  619. if (ppIWiaItems)
  620. {
  621. CComPtr<IWiaTransferHelper> pWiaTransferHelper;
  622. hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaTransferHelper, (void**)&pWiaTransferHelper );
  623. if (SUCCEEDED(hr))
  624. {
  625. for (int i=0;i<nItemCount && SUCCEEDED(hr) && hr != S_FALSE;i++)
  626. {
  627. IWiaDataCallback *pWiaDataCallback = CWiaDataCallbackBase::CreateInstance();
  628. if (pWiaDataCallback)
  629. {
  630. TCHAR szTempPath[MAX_PATH], szFilename[MAX_PATH] = TEXT("");
  631. GetTempPath( ARRAYSIZE(szTempPath), szTempPath );
  632. GetTempFileName( szTempPath, TEXT("acq"), 0, szFilename );
  633. CComPtr<IWiaSupportedFormats> pWiaSupportedFormats;
  634. hr = pWiaTransferHelper->QueryInterface( IID_IWiaSupportedFormats, (void**)&pWiaSupportedFormats );
  635. if (SUCCEEDED(hr))
  636. {
  637. hr = pWiaSupportedFormats->Initialize( ppIWiaItems[i], TYMED_FILE );
  638. if (SUCCEEDED(hr))
  639. {
  640. GUID cf;
  641. hr = pWiaSupportedFormats->GetDefaultClipboardFileFormat( &cf );
  642. if (SUCCEEDED(hr))
  643. {
  644. CSimpleStringWide strTemp(CSimpleStringConvert::WideString(CSimpleString(szFilename)));
  645. WCHAR szTemp[MAX_PATH];
  646. lstrcpyW( szTemp, strTemp.String() );
  647. hr = pWiaSupportedFormats->ChangeClipboardFileExtension( cf, szTemp, ARRAYSIZE(szTemp) );
  648. if (SUCCEEDED(hr))
  649. {
  650. lstrcpy( szFilename, CSimpleStringConvert::NaturalString(CSimpleStringWide(szTemp)));
  651. hr = pWiaTransferHelper->TransferItemFile( ppIWiaItems[i], m_hWnd, 0, cf, CSimpleStringConvert::WideString(CSimpleString(szFilename)).String(), pWiaDataCallback, TYMED_FILE );
  652. if (S_OK == hr)
  653. {
  654. CSimpleString strNaturalFilename = CSimpleStringConvert::NaturalString(CSimpleString(szFilename));
  655. DestroyBitmap();
  656. CGdiPlusHelper().LoadAndScale( m_hOriginalBitmap, strNaturalFilename );
  657. InvalidateRect( m_hWnd, NULL, TRUE );
  658. UpdateWindow( m_hWnd );
  659. MessageBox( m_hWnd, CSimpleString().Format( TEXT("File transfer appeared to work: %s"), strNaturalFilename.String() ), TEXT("Debug"), 0 );
  660. DeleteFile( strNaturalFilename );
  661. hr = pWiaSupportedFormats->Initialize( ppIWiaItems[i], TYMED_CALLBACK );
  662. if (SUCCEEDED(hr))
  663. {
  664. hr = pWiaSupportedFormats->GetDefaultClipboardFileFormat( &cf );
  665. if (SUCCEEDED(hr))
  666. {
  667. hr = pWiaTransferHelper->TransferItemBanded( ppIWiaItems[i], m_hWnd, 0, cf, 0, pWiaDataCallback );
  668. if (S_OK == hr)
  669. {
  670. MessageBox( m_hWnd, TEXT("Banded transfer appeared to work"), TEXT("Debug"), 0 );
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. }
  680. ppIWiaItems[i]->Release();
  681. }
  682. }
  683. LocalFree( ppIWiaItems );
  684. }
  685. }
  686. }
  687. }
  688. if (FAILED(hr))
  689. {
  690. TCHAR szMessage[MAX_PATH];
  691. wsprintf( szMessage, TEXT("HRESULT: 0x%08X"), hr );
  692. MessageBox( NULL, szMessage, TEXT("Some kinda error happened"), 0 );
  693. WIA_PRINTHRESULT((hr,TEXT("ScannerAcquireDialog failed")));
  694. }
  695. }
  696. bool LoadAndScale( LPCTSTR pszImageName )
  697. {
  698. const int cnScaleX = 800;
  699. const int cnScaleY = 600;
  700. const int bScaleSmallImages = true;
  701. bool bResult = false;
  702. CGdiPlusHelper GdiPlusHelper;
  703. HRESULT hr = GdiPlusHelper.LoadAndScale( m_hOriginalBitmap, pszImageName, cnScaleX, cnScaleY, bScaleSmallImages );
  704. if (SUCCEEDED(hr))
  705. {
  706. if (m_hOriginalBitmap)
  707. {
  708. InvalidateRect( m_hWnd, NULL, TRUE );
  709. UpdateWindow(m_hWnd);
  710. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) succeeded"), m_hOriginalBitmap, pszImageName, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONINFORMATION );
  711. bResult = true;
  712. }
  713. else
  714. {
  715. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with a NULL HBITMAP"), m_hOriginalBitmap, pszImageName, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  716. }
  717. }
  718. else
  719. {
  720. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with an HRESULT of %08X"), m_hOriginalBitmap, pszImageName, cnScaleX, cnScaleY, bScaleSmallImages, hr ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  721. }
  722. return bResult;
  723. }
  724. void RotateFile( bool bJpeg )
  725. {
  726. const int cnDegrees = 90;
  727. const int bScaleSmallImages = true;
  728. TCHAR szSourceImage[MAX_PATH] = {0};
  729. OPENFILENAME OpenFileName = {0};
  730. OpenFileName.lStructSize = sizeof(OpenFileName);
  731. OpenFileName.lpstrFilter = bJpeg ? TEXT("JPEG Files\0*.jpg;*.jpe;*.jpeg\0") : TEXT("All files\0*.*\0");
  732. OpenFileName.lpstrFile = szSourceImage;
  733. OpenFileName.nMaxFile = ARRAYSIZE(szSourceImage);
  734. if (GetOpenFileName(&OpenFileName))
  735. {
  736. TCHAR szTempDir[MAX_PATH];
  737. if (GetTempPath(ARRAYSIZE(szTempDir),szTempDir))
  738. {
  739. TCHAR szTempTargetFile[MAX_PATH];
  740. if (GetTempFileName(szTempDir,TEXT("taq"), 0, szTempTargetFile ))
  741. {
  742. CGdiPlusHelper GdiPlusHelper;
  743. HRESULT hr = GdiPlusHelper.Rotate( CSimpleStringConvert::WideString(CSimpleString(szSourceImage)), CSimpleStringConvert::WideString(CSimpleString(szTempTargetFile)), cnDegrees, IID_NULL );
  744. if (SUCCEEDED(hr))
  745. {
  746. if (LoadAndScale(szTempTargetFile))
  747. {
  748. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.Rotate(\n szSourceImage = %s, \n szTempTargetFile = %s, \n cnDegrees = %d\n) succeeded"), szSourceImage, szTempTargetFile, cnDegrees ), TEXT("RotateFile"), MB_ICONINFORMATION );
  749. }
  750. }
  751. else
  752. {
  753. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.Rotate(\n szSourceImage = %s, \n szTempTargetFile = %s, \n cnDegrees = %d\n) failed with HRESULT %08X"), szSourceImage, szTempTargetFile, cnDegrees, hr ), TEXT("RotateFile"), MB_ICONHAND );
  754. }
  755. }
  756. }
  757. }
  758. }
  759. void OnGdiRotateFileNonJpeg( WPARAM, LPARAM )
  760. {
  761. RotateFile(false);
  762. }
  763. void OnGdiRotateFileJpeg( WPARAM, LPARAM )
  764. {
  765. RotateFile(true);
  766. }
  767. void OnGdiLoadAndScaleImage( WPARAM, LPARAM )
  768. {
  769. const int cnScaleX = 800;
  770. const int cnScaleY = 600;
  771. const int bScaleSmallImages = true;
  772. DestroyBitmap();
  773. TCHAR szSourceImage[MAX_PATH] = {0};
  774. OPENFILENAME OpenFileName = {0};
  775. OpenFileName.lStructSize = sizeof(OpenFileName);
  776. OpenFileName.lpstrFilter = TEXT("All files\0*.*\0");
  777. OpenFileName.lpstrFile = szSourceImage;
  778. OpenFileName.nMaxFile = ARRAYSIZE(szSourceImage);
  779. if (GetOpenFileName(&OpenFileName))
  780. {
  781. CGdiPlusHelper GdiPlusHelper;
  782. HRESULT hr = GdiPlusHelper.LoadAndScale( m_hOriginalBitmap, szSourceImage, cnScaleX, cnScaleY, bScaleSmallImages );
  783. if (SUCCEEDED(hr))
  784. {
  785. if (m_hOriginalBitmap)
  786. {
  787. InvalidateRect( m_hWnd, NULL, TRUE );
  788. UpdateWindow(m_hWnd);
  789. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) succeeded"), m_hOriginalBitmap, szSourceImage, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONINFORMATION );
  790. }
  791. else
  792. {
  793. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with a NULL HBITMAP"), m_hOriginalBitmap, szSourceImage, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  794. }
  795. }
  796. else
  797. {
  798. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n szSourceImage = %s, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with an HRESULT of %08X"), m_hOriginalBitmap, szSourceImage, cnScaleX, cnScaleY, bScaleSmallImages, hr ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  799. }
  800. }
  801. }
  802. void OnGdiLoadAndScaleStream( WPARAM, LPARAM )
  803. {
  804. const int cnScaleX = 800;
  805. const int cnScaleY = 600;
  806. const int bScaleSmallImages = true;
  807. DestroyBitmap();
  808. CComPtr<IStream> pStream;
  809. //HRESULT hr = URLOpenBlockingStream( NULL, TEXT("http://www.ivory.org/spiders/araneus.diadematus-4.jpg"), &pStream, 0, NULL );
  810. HRESULT hr = URLOpenBlockingStream( NULL, TEXT("http://orenr04:2869/upnphost/ssisapi.dll?ImageFile=nature3.jpg"), &pStream, 0, NULL );
  811. if (SUCCEEDED(hr))
  812. {
  813. CGdiPlusHelper GdiPlusHelper;
  814. hr = GdiPlusHelper.LoadAndScale( m_hOriginalBitmap, pStream, cnScaleX, cnScaleY, bScaleSmallImages );
  815. if (SUCCEEDED(hr))
  816. {
  817. if (m_hOriginalBitmap)
  818. {
  819. InvalidateRect( m_hWnd, NULL, TRUE );
  820. UpdateWindow(m_hWnd);
  821. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n pStream = %p, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) succeeded"), m_hOriginalBitmap, pStream, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONINFORMATION );
  822. }
  823. else
  824. {
  825. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n pStream = %p, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with a NULL HBITMAP"), m_hOriginalBitmap, pStream, cnScaleX, cnScaleY, bScaleSmallImages ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  826. }
  827. }
  828. else
  829. {
  830. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.LoadAndScale(\n m_hOriginalBitmap = %p, \n pStream = %p, \n cnScaleX = %d, \n cnScaleY = %d, \n bScaleSmallImages = %d\n) failed with an HRESULT of %08X"), m_hOriginalBitmap, pStream, cnScaleX, cnScaleY, bScaleSmallImages, hr ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  831. }
  832. }
  833. else
  834. {
  835. MessageBox( m_hWnd, CSimpleString().Format( TEXT("URLOpenBlockingStream failed: %08X" ), hr ), TEXT("OnGdiLoadAndScaleImage"), MB_ICONHAND );
  836. }
  837. }
  838. void OnGdiConvertFile( WPARAM, LPARAM )
  839. {
  840. #if 0
  841. TCHAR szInputFilename[MAX_PATH];
  842. OPENFILENAME OpenFileName = {0};
  843. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  844. OpenFileName.hwndOwner = m_hWnd;
  845. OpenFileName.hInstance = g_hInstance;
  846. OpenFileName.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
  847. OpenFileName.lpstrFile = szInputFilename;
  848. OpenFileName.nMaxFile = ARRAYSIZE(szInputFilename);
  849. OpenFileName.lpstrTitle = TEXT("Choose File to Convert");
  850. OpenFileName.Flags = OFN_ENABLESIZING|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
  851. if (GetOpenFileName(&OpenFileName))
  852. {
  853. TCHAR szOutputFilename[MAX_PATH] = {0};
  854. OPENFILENAME SaveFileName = {0};
  855. SaveFileName.lStructSize = sizeof(OPENFILENAME);
  856. SaveFileName.hwndOwner = m_hWnd;
  857. SaveFileName.hInstance = g_hInstance;
  858. SaveFileName.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
  859. SaveFileName.lpstrFile = szOutputFilename;
  860. SaveFileName.nMaxFile = ARRAYSIZE(szOutputFilename);
  861. SaveFileName.lpstrTitle = TEXT("Choose output file and type");
  862. SaveFileName.Flags = OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  863. if (GetSaveFileName(&SaveFileName))
  864. {
  865. }
  866. }
  867. #else
  868. CMessageBoxEx::MessageBox( m_hWnd, TEXT("Not implemented"), TEXT("testacqd"), CMessageBoxEx::MBEX_OK|CMessageBoxEx::MBEX_ICONWARNING );
  869. #endif
  870. }
  871. void OnExploreWiaDevice( WPARAM, LPARAM )
  872. {
  873. CWaitCursor wc;
  874. CComPtr<IWiaDevMgr> pIWiaDevMgr;
  875. HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void**)&pIWiaDevMgr );
  876. if (SUCCEEDED(hr))
  877. {
  878. CComPtr<IWiaItem> pWiaItemRoot;
  879. BSTR bstrDeviceId = NULL;
  880. hr = pIWiaDevMgr->SelectDeviceDlgID( m_hWnd, SELECT_DEVICE_TYPE, 0, &bstrDeviceId );
  881. if (S_OK == hr)
  882. {
  883. hr = WiaUiUtil::ExploreWiaDevice( bstrDeviceId );
  884. }
  885. }
  886. if (!SUCCEEDED(hr))
  887. {
  888. CMessageBoxEx::MessageBox( m_hWnd, CSimpleString().Format(TEXT("Result: %08X"),hr), TEXT("testacqd"), CMessageBoxEx::MBEX_OK|CMessageBoxEx::MBEX_ICONINFORMATION );
  889. }
  890. }
  891. void OnGdiRotateHBITMAP( WPARAM, LPARAM )
  892. {
  893. if (m_hOriginalBitmap)
  894. {
  895. HBITMAP hNewBitmap;
  896. CGdiPlusHelper GdiPlusHelper;
  897. GdiPlusHelper.Rotate( m_hOriginalBitmap, hNewBitmap, 90 );
  898. DestroyBitmap();
  899. m_hOriginalBitmap = hNewBitmap;
  900. InvalidateRect( m_hWnd, NULL, TRUE );
  901. UpdateWindow(m_hWnd);
  902. }
  903. }
  904. void OnGdiDisplayDecoderExtensions( WPARAM, LPARAM )
  905. {
  906. CSimpleString strExtensions;
  907. HRESULT hr = CGdiPlusHelper().ConstructDecoderExtensionSearchStrings( strExtensions );
  908. if (SUCCEEDED(hr))
  909. {
  910. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.ConstructDecoderExtensionSearchStrings() succeeded and returned strExtensions = %s"), strExtensions.String() ), TEXT("OnGdiDisplayDecoderExtensions"), MB_ICONINFORMATION );
  911. }
  912. else
  913. {
  914. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.ConstructDecoderExtensionSearchStrings() returned HRESULT = %08X"), hr ), TEXT("OnGdiDisplayDecoderExtensions"), MB_ICONINFORMATION );
  915. }
  916. }
  917. void OnGdiDisplayEncoderExtensions( WPARAM, LPARAM )
  918. {
  919. CSimpleString strExtensions;
  920. HRESULT hr = CGdiPlusHelper().ConstructEncoderExtensionSearchStrings( strExtensions );
  921. if (SUCCEEDED(hr))
  922. {
  923. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.ConstructEncoderExtensionSearchStrings() succeeded and returned strExtensions = %s"), strExtensions.String() ), TEXT("OnGdiDisplayEncoderExtensions"), MB_ICONINFORMATION );
  924. }
  925. else
  926. {
  927. MessageBox( m_hWnd, CSimpleString().Format( TEXT("GdiPlusHelper.ConstructEncoderExtensionSearchStrings() returned HRESULT = %08X"), hr ), TEXT("OnGdiDisplayEncoderExtensions"), MB_ICONINFORMATION );
  928. }
  929. }
  930. void OnGdiSaveMultipleImagesAsMultiPage( WPARAM, LPARAM )
  931. {
  932. LPTSTR pszFiles = new TCHAR[0xFFFF];
  933. if (pszFiles)
  934. {
  935. OPENFILENAME OpenFileName = {0};
  936. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  937. OpenFileName.hwndOwner = m_hWnd;
  938. OpenFileName.hInstance = g_hInstance;
  939. OpenFileName.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
  940. OpenFileName.lpstrFile = pszFiles;
  941. OpenFileName.nMaxFile = 0xFFFF;
  942. OpenFileName.lpstrTitle = TEXT("Choose Files to Convert to a multi-page TIFF");
  943. OpenFileName.Flags = OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
  944. if (GetOpenFileName(&OpenFileName))
  945. {
  946. CMultiString strItems(pszFiles);
  947. if (strItems.Size())
  948. {
  949. CSimpleDynamicArray<CSimpleStringWide> strFiles;
  950. if (strItems.Size() == 1)
  951. {
  952. strFiles.Append(CSimpleStringConvert::WideString(CSimpleString(strItems[0])));
  953. }
  954. else
  955. {
  956. CSimpleString strDirectory = strItems[0];
  957. if (!strDirectory.MatchLastCharacter(TEXT('\\')))
  958. {
  959. strDirectory += TEXT("\\");
  960. }
  961. for (int i=1;i<strItems.Size();i++)
  962. {
  963. strFiles.Append(CSimpleStringConvert::WideString(CSimpleString(strDirectory + strItems[i])));
  964. }
  965. }
  966. for (int i=0;i<strFiles.Size();i++)
  967. {
  968. WIA_TRACE((TEXT("strFiles[i] = %ws"), strFiles[i].String()));
  969. }
  970. TCHAR szOutputFilename[MAX_PATH] = {0};
  971. OPENFILENAME SaveFileName = {0};
  972. SaveFileName.lStructSize = sizeof(OPENFILENAME);
  973. SaveFileName.hwndOwner = m_hWnd;
  974. SaveFileName.hInstance = g_hInstance;
  975. SaveFileName.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
  976. SaveFileName.lpstrFile = szOutputFilename;
  977. SaveFileName.nMaxFile = ARRAYSIZE(szOutputFilename);
  978. SaveFileName.lpstrTitle = TEXT("Select a name for your multi-page TIFF");
  979. SaveFileName.Flags = OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  980. if (GetSaveFileName(&SaveFileName))
  981. {
  982. HRESULT hr = CGdiPlusHelper().SaveMultipleImagesAsMultiPage( strFiles, CSimpleStringConvert::WideString(CSimpleString(szOutputFilename)), Gdiplus::ImageFormatTIFF );
  983. if (SUCCEEDED(hr))
  984. {
  985. MessageBox( m_hWnd, TEXT("CGdiPlusHelper().SaveMultipleImagesAsMultiPage() succeeded"), TEXT("OnGdiDisplayDecoderExtensions"), MB_ICONINFORMATION );
  986. }
  987. else
  988. {
  989. MessageBox( m_hWnd, CSimpleString().Format( TEXT("CGdiPlusHelper().SaveMultipleImagesAsMultiPage() returned HRESULT = %08X"), hr ), TEXT("OnGdiDisplayDecoderExtensions"), MB_ICONINFORMATION );
  990. }
  991. }
  992. }
  993. }
  994. delete[] pszFiles;
  995. }
  996. }
  997. void OnGdiIncreaseThreshold( WPARAM, LPARAM )
  998. {
  999. if (m_nThreshold != 100)
  1000. {
  1001. m_nThreshold++;
  1002. if (m_hTransformedBitmap)
  1003. {
  1004. DeleteObject(m_hTransformedBitmap);
  1005. m_hTransformedBitmap = NULL;
  1006. }
  1007. CGdiPlusHelper().SetThreshold( m_hOriginalBitmap, m_hTransformedBitmap, m_nThreshold );
  1008. InvalidateRect( m_hWnd, NULL, FALSE );
  1009. UpdateWindow( m_hWnd );
  1010. }
  1011. }
  1012. void OnGdiDecreaseThreshold( WPARAM, LPARAM )
  1013. {
  1014. if (m_nThreshold != 0)
  1015. {
  1016. m_nThreshold--;
  1017. if (m_hTransformedBitmap)
  1018. {
  1019. DeleteObject(m_hTransformedBitmap);
  1020. m_hTransformedBitmap = NULL;
  1021. }
  1022. CGdiPlusHelper().SetThreshold( m_hOriginalBitmap, m_hTransformedBitmap, m_nThreshold );
  1023. InvalidateRect( m_hWnd, NULL, FALSE );
  1024. UpdateWindow( m_hWnd );
  1025. }
  1026. }
  1027. void OnGdiIncreaseContrast( WPARAM, LPARAM )
  1028. {
  1029. if (m_nContrast != 100)
  1030. {
  1031. m_nContrast++;
  1032. if (m_hTransformedBitmap)
  1033. {
  1034. DeleteObject(m_hTransformedBitmap);
  1035. m_hTransformedBitmap = NULL;
  1036. }
  1037. CGdiPlusHelper().SetBrightnessAndContrast( m_hOriginalBitmap, m_hTransformedBitmap, m_nBrightness, m_nContrast );
  1038. InvalidateRect( m_hWnd, NULL, FALSE );
  1039. UpdateWindow( m_hWnd );
  1040. }
  1041. }
  1042. void OnGdiDecreaseContrast( WPARAM, LPARAM )
  1043. {
  1044. if (m_nContrast != 0)
  1045. {
  1046. m_nContrast--;
  1047. if (m_hTransformedBitmap)
  1048. {
  1049. DeleteObject(m_hTransformedBitmap);
  1050. m_hTransformedBitmap = NULL;
  1051. }
  1052. CGdiPlusHelper().SetBrightnessAndContrast( m_hOriginalBitmap, m_hTransformedBitmap, m_nBrightness, m_nContrast );
  1053. InvalidateRect( m_hWnd, NULL, FALSE );
  1054. UpdateWindow( m_hWnd );
  1055. }
  1056. }
  1057. void OnGdiDecreaseBrightness( WPARAM, LPARAM )
  1058. {
  1059. if (m_nBrightness != 0)
  1060. {
  1061. m_nBrightness--;
  1062. if (m_hTransformedBitmap)
  1063. {
  1064. DeleteObject(m_hTransformedBitmap);
  1065. m_hTransformedBitmap = NULL;
  1066. }
  1067. CGdiPlusHelper().SetBrightnessAndContrast( m_hOriginalBitmap, m_hTransformedBitmap, m_nBrightness, m_nContrast );
  1068. InvalidateRect( m_hWnd, NULL, FALSE );
  1069. UpdateWindow( m_hWnd );
  1070. }
  1071. }
  1072. void OnGdiIncreaseBrightness( WPARAM, LPARAM )
  1073. {
  1074. if (m_nBrightness != 255)
  1075. {
  1076. m_nBrightness++;
  1077. if (m_hTransformedBitmap)
  1078. {
  1079. DeleteObject(m_hTransformedBitmap);
  1080. m_hTransformedBitmap = NULL;
  1081. }
  1082. CGdiPlusHelper().SetBrightnessAndContrast( m_hOriginalBitmap, m_hTransformedBitmap, m_nBrightness, m_nContrast );
  1083. InvalidateRect( m_hWnd, NULL, FALSE );
  1084. UpdateWindow( m_hWnd );
  1085. }
  1086. }
  1087. void OnTestUniversalPnpSlideshowClient( WPARAM, LPARAM )
  1088. {
  1089. CComPtr<IUPnPDeviceFinder> pUPnPDeviceFinder;
  1090. HRESULT hr = CoCreateInstance( CLSID_UPnPDeviceFinder, NULL, CLSCTX_INPROC_SERVER, IID_IUPnPDeviceFinder, (void**)&pUPnPDeviceFinder );
  1091. if (SUCCEEDED(hr))
  1092. {
  1093. CComPtr<IUPnPDevices> pUPnPDevices;
  1094. hr = pUPnPDeviceFinder->FindByType(CSimpleBStr(CSimpleString(TEXT("urn:schemas-upnp-org:device:SlideshowProjector:1"))),0,&pUPnPDevices);
  1095. if (S_OK == hr)
  1096. {
  1097. LONG nDeviceCount=0;
  1098. hr = pUPnPDevices->get_Count(&nDeviceCount);
  1099. if (S_OK == hr)
  1100. {
  1101. CComPtr<IUnknown> pUnknown;
  1102. hr = pUPnPDevices->get__NewEnum(&pUnknown);
  1103. if (S_OK == hr)
  1104. {
  1105. CComPtr<IEnumUnknown> pEnumUnknown;
  1106. hr = pUnknown->QueryInterface( IID_IEnumUnknown, (VOID **)&pEnumUnknown);
  1107. if (S_OK == hr)
  1108. {
  1109. ULONG nDevicesReturned=0;
  1110. CComPtr<IUnknown> pDeviceUnknown;
  1111. hr = pEnumUnknown->Next( 1, &pDeviceUnknown, &nDevicesReturned );
  1112. if (S_OK == hr)
  1113. {
  1114. CComPtr<IUPnPDevice> pUPnPDevice;
  1115. hr = pDeviceUnknown->QueryInterface( IID_IUPnPDevice, (void**)&pUPnPDevice);
  1116. if (S_OK == hr)
  1117. {
  1118. CComPtr<IUPnPServices> pUPnPServices;
  1119. hr= pUPnPDevice->get_Services(&pUPnPServices);
  1120. if (S_OK == hr)
  1121. {
  1122. CComPtr<IUnknown> pUnknown;
  1123. hr = pUPnPServices->get__NewEnum(&pUnknown);
  1124. if (S_OK == hr)
  1125. {
  1126. CComPtr<IEnumUnknown> pEnumUnknown;
  1127. hr = pUnknown->QueryInterface( IID_IEnumUnknown, (void**)&pEnumUnknown );
  1128. if (S_OK == hr)
  1129. {
  1130. hr = pEnumUnknown->Reset();
  1131. while (S_OK == hr)
  1132. {
  1133. ULONG nNumFetched = 0;
  1134. CComPtr<IUnknown> pUnknown;
  1135. hr = pEnumUnknown->Next( 1, &pUnknown, &nNumFetched );
  1136. if (S_OK == hr)
  1137. {
  1138. CComPtr<IUPnPService> pUPnPService;
  1139. hr = pUnknown->QueryInterface(IID_IUPnPService, (void**)&pUPnPService);
  1140. if (S_OK == hr)
  1141. {
  1142. }
  1143. else
  1144. {
  1145. MessageBox( m_hWnd, CSimpleString(TEXT("pUnknown->QueryInterface on IID_IUPnPService failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1146. }
  1147. //
  1148. // Release it
  1149. //
  1150. pUnknown = NULL;
  1151. }
  1152. else if (FAILED(hr))
  1153. {
  1154. MessageBox( m_hWnd, CSimpleString(TEXT("pEnumUnknown->Next() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1155. }
  1156. }
  1157. if (FAILED(hr))
  1158. {
  1159. MessageBox( m_hWnd, CSimpleString(TEXT("pEnumUnknown->Reset() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1160. }
  1161. }
  1162. else
  1163. {
  1164. MessageBox( m_hWnd, CSimpleString(TEXT("pUnknown->QueryInterface on IID_IEnumUnknown failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1165. }
  1166. }
  1167. else
  1168. {
  1169. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPDevice->get_Services() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1170. }
  1171. m_pUPnPService = NULL;
  1172. hr = pUPnPServices->get_Item(CSimpleBStr(TEXT("upnp:id:SlideshowService")),&m_pUPnPService);
  1173. if (S_OK == hr)
  1174. {
  1175. hr = m_pUPnPService->AddCallback( this );
  1176. if (S_OK == hr)
  1177. {
  1178. WIA_TRACE((TEXT("m_pUPnPService->AddCallback SUCCEEDED!")));
  1179. MessageBeep(-1);
  1180. }
  1181. else
  1182. {
  1183. MessageBox( m_hWnd, CSimpleString(TEXT("m_pUPnPService->AddCallback() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1184. }
  1185. }
  1186. else
  1187. {
  1188. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPServices->get_Item() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1189. }
  1190. }
  1191. else
  1192. {
  1193. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPDevice->get_Services() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1194. }
  1195. }
  1196. else
  1197. {
  1198. MessageBox( m_hWnd, CSimpleString(TEXT("pDeviceUnknown->QueryInterface() failed on IID_IUPnPDevice\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1199. }
  1200. }
  1201. else
  1202. {
  1203. MessageBox( m_hWnd, CSimpleString(TEXT("pEnumUnknown->Next() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1204. }
  1205. }
  1206. else
  1207. {
  1208. MessageBox( m_hWnd, CSimpleString(TEXT("pUnknown->QueryInterface() failed on IID_IEnumUnknown\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1209. }
  1210. }
  1211. else
  1212. {
  1213. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPDevices->get__NewEnum() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1214. }
  1215. }
  1216. else
  1217. {
  1218. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPDevices->get_Count() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1219. }
  1220. }
  1221. else
  1222. {
  1223. MessageBox( m_hWnd, CSimpleString(TEXT("pUPnPDeviceFinder->FindByType() failed\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1224. }
  1225. }
  1226. else
  1227. {
  1228. MessageBox( m_hWnd, CSimpleString(TEXT("CoCreateInstance failed on CLSID_UPnPDeviceFinder\n\n")) + WiaUiUtil::GetErrorTextFromHResult(hr), TEXT("OnTestUniversalPnpSlideshowClient"), MB_ICONINFORMATION );
  1229. }
  1230. }
  1231. void OnTestUniversalPnpSlideshowClientStop( WPARAM, LPARAM )
  1232. {
  1233. m_pUPnPService = NULL;
  1234. }
  1235. void OnPublishWizard( WPARAM, LPARAM )
  1236. {
  1237. LPTSTR pszFiles = new TCHAR[0xFFFF];
  1238. if (pszFiles)
  1239. {
  1240. OPENFILENAME OpenFileName = {0};
  1241. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  1242. OpenFileName.hwndOwner = m_hWnd;
  1243. OpenFileName.hInstance = g_hInstance;
  1244. OpenFileName.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
  1245. OpenFileName.lpstrFile = pszFiles;
  1246. OpenFileName.nMaxFile = 0xFFFF;
  1247. OpenFileName.lpstrTitle = TEXT("Choose Files to Upload");
  1248. OpenFileName.Flags = OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
  1249. if (GetOpenFileName(&OpenFileName))
  1250. {
  1251. CMultiString strItems(pszFiles);
  1252. if (strItems.Size())
  1253. {
  1254. CSimpleDynamicArray<CSimpleString> strFiles;
  1255. if (strItems.Size() == 1)
  1256. {
  1257. strFiles.Append(strItems[0]);
  1258. }
  1259. else
  1260. {
  1261. CSimpleString strDirectory = strItems[0];
  1262. if (!strDirectory.MatchLastCharacter(TEXT('\\')))
  1263. {
  1264. strDirectory += TEXT("\\");
  1265. }
  1266. for (int i=1;i<strItems.Size();i++)
  1267. {
  1268. strFiles.Append(strDirectory + strItems[i]);
  1269. }
  1270. }
  1271. for (int i=0;i<strFiles.Size();i++)
  1272. {
  1273. WIA_TRACE((TEXT("strFiles[i] = %s"), strFiles[i].String()));
  1274. }
  1275. HRESULT hr = NetPublishingWizard::RunNetPublishingWizard( strFiles );
  1276. if (FAILED(hr))
  1277. {
  1278. WIA_PRINTHRESULT((hr,TEXT("NetPublishingWizard::RunNetPublishingWizard returned")));
  1279. }
  1280. }
  1281. }
  1282. delete[] pszFiles;
  1283. }
  1284. }
  1285. void OnWiaSelectDeviceDlgId( WPARAM, LPARAM )
  1286. {
  1287. CComPtr<IWiaDevMgr> pIWiaDevMgr;
  1288. HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void**)&pIWiaDevMgr );
  1289. if (SUCCEEDED(hr))
  1290. {
  1291. CComPtr<IWiaItem> pWiaItemRoot;
  1292. BSTR bstrDeviceId = NULL;
  1293. hr = pIWiaDevMgr->SelectDeviceDlgID( m_hWnd, SELECT_DEVICE_TYPE, 0, &bstrDeviceId );
  1294. if (SUCCEEDED(hr) && (S_FALSE != hr))
  1295. {
  1296. MessageBox( m_hWnd, CSimpleStringConvert::NaturalString(CSimpleStringWide(bstrDeviceId)), TEXT("Device ID:"), MB_ICONINFORMATION );
  1297. }
  1298. }
  1299. if (FAILED(hr))
  1300. {
  1301. WIA_PRINTHRESULT((hr,TEXT("OnSelectDeviceDlgId returned")));
  1302. }
  1303. }
  1304. void OnWiaWizard( WPARAM, LPARAM )
  1305. {
  1306. HRESULT hr = RunWiaWizard::RunWizard( NULL, m_hWnd );
  1307. if (FAILED(hr))
  1308. {
  1309. WIA_PRINTHRESULT((hr,TEXT("RunWiaWizard::RunWizard returned")));
  1310. }
  1311. }
  1312. void OnMbox( WPARAM wParam, LPARAM )
  1313. {
  1314. LPCTSTR pszTitle = TEXT("Message Box Test Title");
  1315. LPCTSTR pszMessage = TEXT("Message Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\nMessage Box Test Message\n(LAST) Message Box Test Message");
  1316. LPCTSTR pszFormat = TEXT("This is a formatted string: \"%s\", and this is a formatted number: %d");
  1317. UINT nTitleId = IDS_MESSAGEBOXTESTTITLE;
  1318. UINT nMessageId = IDS_MESSAGEBOXTESTMESSAGE;
  1319. UINT nFormatId = IDS_MESSAGEBOXTESTFORMAT;
  1320. UINT nFlags = m_nMessageBoxExFlags;
  1321. bool bHideFutureMessages = true;
  1322. HINSTANCE hInstance = g_hInstance;
  1323. HWND hWndParent = m_hWnd;
  1324. LPCTSTR pszTestString = TEXT("This is a test string");
  1325. int nTestNumber = 1234567890;
  1326. INT_PTR nResult = 0;
  1327. switch (LOWORD(wParam))
  1328. {
  1329. case ID_MBOX_FORM1:
  1330. nResult = CMessageBoxEx::MessageBox( hWndParent, pszMessage, pszTitle, nFlags, bHideFutureMessages );
  1331. break;
  1332. case ID_MBOX_FORM2:
  1333. nResult = CMessageBoxEx::MessageBox( hWndParent, pszMessage, pszTitle, nFlags );
  1334. break;
  1335. case ID_MBOX_FORM3:
  1336. nResult = CMessageBoxEx::MessageBox( pszMessage, pszTitle, nFlags );
  1337. break;
  1338. case ID_MBOX_FORM4:
  1339. nResult = CMessageBoxEx::MessageBox( hWndParent, hInstance, nMessageId, nTitleId, nFlags, bHideFutureMessages );
  1340. break;
  1341. case ID_MBOX_FORM5:
  1342. nResult = CMessageBoxEx::MessageBox( hWndParent, pszTitle, nFlags, pszFormat, pszTestString, nTestNumber );
  1343. break;
  1344. case ID_MBOX_FORM6:
  1345. nResult = CMessageBoxEx::MessageBox( hWndParent, pszTitle, nFlags, bHideFutureMessages, pszFormat, pszTestString, nTestNumber );
  1346. break;
  1347. case ID_MBOX_FORM7:
  1348. nResult = CMessageBoxEx::MessageBox( hWndParent, hInstance, nTitleId, nFlags, nFormatId, pszTestString, nTestNumber );
  1349. break;
  1350. }
  1351. MessageBox( m_hWnd, CSimpleString().Format( TEXT("CMessageBoxEx::MessageBox returned %d, and the value of bHideFutureMessages is %d"), nResult, bHideFutureMessages ), TEXT("Result"), MB_ICONINFORMATION );
  1352. }
  1353. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  1354. {
  1355. SC_BEGIN_COMMAND_HANDLERS()
  1356. {
  1357. SC_HANDLE_COMMAND(ID_PROGRAM_EXIT,OnFileExit);
  1358. SC_HANDLE_COMMAND(ID_WIA_DEVICEDLG,OnWiaDeviceDlg);
  1359. SC_HANDLE_COMMAND(ID_WIA_SELECTDEVICEID,OnWiaSelectDeviceDlgId);
  1360. SC_HANDLE_COMMAND(ID_PROGRESS_TESTPROGRESS,OnProgressTestProgress);
  1361. SC_HANDLE_COMMAND(ID_PROGRESS_SETFLAGS,OnProgressSetFlags);
  1362. SC_HANDLE_COMMAND(ID_GDI_ROTATEFILENONJPEG,OnGdiRotateFileNonJpeg);
  1363. SC_HANDLE_COMMAND(ID_GDI_ROTATEFILEJPEG,OnGdiRotateFileJpeg);
  1364. SC_HANDLE_COMMAND(ID_GDI_ROTATEHBITMAP,OnGdiRotateHBITMAP);
  1365. SC_HANDLE_COMMAND(ID_GDI_LOADANDSCALEIMAGE,OnGdiLoadAndScaleImage);
  1366. SC_HANDLE_COMMAND(ID_GDI_LOADANDSCALESTREAM,OnGdiLoadAndScaleStream);
  1367. SC_HANDLE_COMMAND(ID_GDI_CONVERTFILE,OnGdiConvertFile);
  1368. SC_HANDLE_COMMAND(ID_GDI_DISPLAYDECODEREXTENSIONS,OnGdiDisplayDecoderExtensions);
  1369. SC_HANDLE_COMMAND(ID_GDI_DISPLAYENCODEREXTENSIONS,OnGdiDisplayEncoderExtensions);
  1370. SC_HANDLE_COMMAND(ID_GDI_SAVEMULTIPLEIMAGESASMULTIPAGE, OnGdiSaveMultipleImagesAsMultiPage);
  1371. SC_HANDLE_COMMAND(ID_GDI_INCREASETHRESHOLD,OnGdiIncreaseThreshold);
  1372. SC_HANDLE_COMMAND(ID_GDI_DECREASETHRESHOLD,OnGdiDecreaseThreshold);
  1373. SC_HANDLE_COMMAND(ID_GDI_INCREASECONTRAST,OnGdiIncreaseContrast);
  1374. SC_HANDLE_COMMAND(ID_GDI_DECREASECONTRAST,OnGdiDecreaseContrast);
  1375. SC_HANDLE_COMMAND(ID_GDI_INCREASEBRIGHTNESS,OnGdiIncreaseBrightness);
  1376. SC_HANDLE_COMMAND(ID_GDI_DECREASEBRIGHTNESS,OnGdiDecreaseBrightness);
  1377. SC_HANDLE_COMMAND(ID_WIZARD_PUBLISH_WIZARD,OnPublishWizard);
  1378. SC_HANDLE_COMMAND(ID_WIZARD_ACQUIRE_WIZARD,OnWiaWizard);
  1379. SC_HANDLE_COMMAND(ID_WIZARD_EXPLOREWIADEVICE,OnExploreWiaDevice);
  1380. SC_HANDLE_COMMAND(ID_MBOX_FORM1,OnMbox);
  1381. SC_HANDLE_COMMAND(ID_MBOX_FORM2,OnMbox);
  1382. SC_HANDLE_COMMAND(ID_MBOX_FORM3,OnMbox);
  1383. SC_HANDLE_COMMAND(ID_MBOX_FORM4,OnMbox);
  1384. SC_HANDLE_COMMAND(ID_MBOX_FORM5,OnMbox);
  1385. SC_HANDLE_COMMAND(ID_MBOX_FORM6,OnMbox);
  1386. SC_HANDLE_COMMAND(ID_MBOX_FORM7,OnMbox);
  1387. SC_HANDLE_COMMAND(ID_MBOX_SETFLAGS,OnMBoxSetFlags);
  1388. SC_HANDLE_COMMAND(ID_UPNP_FINDSERVERANDREGISTER,OnTestUniversalPnpSlideshowClient);
  1389. SC_HANDLE_COMMAND(ID_UPNP_STOP,OnTestUniversalPnpSlideshowClientStop);
  1390. }
  1391. SC_END_COMMAND_HANDLERS();
  1392. }
  1393. void FillRect( HDC hDC, int nLeft, int nTop, int nRight, int nBottom, HBRUSH hBrush )
  1394. {
  1395. RECT rcFill = {nLeft,nTop,nRight,nBottom};
  1396. if (nLeft < nRight && nTop < nBottom)
  1397. {
  1398. ::FillRect( hDC, &rcFill, hBrush );
  1399. }
  1400. }
  1401. void FillRectDifference( HDC hDC, const RECT &rcMain, const RECT &rcDiff, HBRUSH hBrush )
  1402. {
  1403. //
  1404. // Top
  1405. //
  1406. FillRect( hDC, rcMain.left, rcMain.top, rcMain.right, rcDiff.top, hBrush );
  1407. //
  1408. // Bottom
  1409. //
  1410. FillRect( hDC, rcMain.left, rcDiff.bottom, rcMain.right, rcMain.bottom, hBrush );
  1411. //
  1412. // Left
  1413. //
  1414. FillRect( hDC, rcMain.left, rcDiff.top, rcDiff.left, rcDiff.bottom, hBrush );
  1415. //
  1416. // Right
  1417. //
  1418. FillRect( hDC, rcDiff.right, rcDiff.top, rcMain.right, rcMain.bottom, hBrush );
  1419. }
  1420. LRESULT OnEraseBkGnd( WPARAM, LPARAM )
  1421. {
  1422. return TRUE;
  1423. }
  1424. LRESULT OnSize( WPARAM, LPARAM )
  1425. {
  1426. InvalidateRect( m_hWnd, NULL, FALSE );
  1427. UpdateWindow( m_hWnd );
  1428. return 0;
  1429. }
  1430. LRESULT OnPaint( WPARAM, LPARAM )
  1431. {
  1432. PAINTSTRUCT ps;
  1433. HDC hDC = BeginPaint( m_hWnd, &ps );
  1434. if (hDC)
  1435. {
  1436. HBITMAP hBitmap = m_hOriginalBitmap;
  1437. if (m_hTransformedBitmap)
  1438. {
  1439. hBitmap = m_hTransformedBitmap;
  1440. }
  1441. if (hBitmap)
  1442. {
  1443. BITMAP bm = {0};
  1444. if (GetObject(hBitmap,sizeof(BITMAP),&bm))
  1445. {
  1446. HDC hCompatDC = CreateCompatibleDC(hDC);
  1447. if (hCompatDC)
  1448. {
  1449. RECT rcClient;
  1450. GetClientRect( m_hWnd, &rcClient );
  1451. RECT rcImage;
  1452. rcImage.left = rcClient.left + (WiaUiUtil::RectWidth(rcClient)-bm.bmWidth)/2;
  1453. rcImage.top = rcClient.left + (WiaUiUtil::RectHeight(rcClient)-bm.bmHeight)/2;
  1454. rcImage.right = rcImage.left + bm.bmWidth;
  1455. rcImage.bottom = rcImage.top + bm.bmHeight;
  1456. HBITMAP hOldBitmap = reinterpret_cast<HBITMAP>(SelectObject(hCompatDC,hBitmap));
  1457. BitBlt( hDC, rcImage.left, rcImage.top, bm.bmWidth, bm.bmHeight, hCompatDC, 0, 0, SRCCOPY );
  1458. FillRectDifference( hDC, rcClient, rcImage, GetStockBrush(BLACK_BRUSH) );
  1459. SelectObject(hCompatDC,hOldBitmap);
  1460. DeleteDC(hCompatDC);
  1461. }
  1462. }
  1463. }
  1464. EndPaint( m_hWnd, &ps );
  1465. }
  1466. return 0;
  1467. }
  1468. LRESULT OnInitMenu( WPARAM wParam, LPARAM )
  1469. {
  1470. HMENU hMenu = reinterpret_cast<HMENU>(wParam);
  1471. if (hMenu)
  1472. {
  1473. EnableMenuItem( hMenu, ID_UPNP_FINDSERVERANDREGISTER, m_pUPnPService ? MF_GRAYED|MF_BYCOMMAND : MF_ENABLED|MF_BYCOMMAND );
  1474. EnableMenuItem( hMenu, ID_UPNP_STOP, m_pUPnPService ? MF_ENABLED|MF_BYCOMMAND : MF_GRAYED|MF_BYCOMMAND );
  1475. }
  1476. return 0;
  1477. }
  1478. static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1479. {
  1480. SC_BEGIN_MESSAGE_HANDLERS(CMiscUnitTestWindow)
  1481. {
  1482. SC_HANDLE_MESSAGE( WM_DESTROY, OnDestroy );
  1483. SC_HANDLE_MESSAGE( WM_CREATE, OnCreate );
  1484. SC_HANDLE_MESSAGE( WM_COMMAND, OnCommand );
  1485. SC_HANDLE_MESSAGE( WM_PAINT, OnPaint );
  1486. SC_HANDLE_MESSAGE( WM_ERASEBKGND, OnEraseBkGnd );
  1487. SC_HANDLE_MESSAGE( WM_SIZE, OnSize );
  1488. SC_HANDLE_MESSAGE( WM_INITMENU, OnInitMenu );
  1489. SC_HANDLE_MESSAGE( PWM_DISPLAYNEWIMAGE, OnDisplayNewImage );
  1490. }
  1491. SC_END_MESSAGE_HANDLERS();
  1492. }
  1493. public:
  1494. static bool RegisterClass( HINSTANCE hInstance, LPCTSTR pszClassName )
  1495. {
  1496. WNDCLASSEX wcex;
  1497. ZeroMemory(&wcex,sizeof(wcex));
  1498. wcex.cbSize = sizeof(wcex);
  1499. if (!GetClassInfoEx( hInstance, pszClassName, &wcex ))
  1500. {
  1501. ZeroMemory(&wcex,sizeof(wcex));
  1502. wcex.cbSize = sizeof(wcex);
  1503. wcex.style = 0;
  1504. wcex.lpfnWndProc = (WNDPROC)WndProc;
  1505. wcex.cbClsExtra = 0;
  1506. wcex.cbWndExtra = 0;
  1507. wcex.hInstance = hInstance;
  1508. wcex.hIcon = 0;
  1509. wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
  1510. wcex.hbrBackground = NULL;
  1511. wcex.lpszMenuName = NULL;
  1512. wcex.lpszClassName = pszClassName;
  1513. wcex.hIconSm = 0;
  1514. if (!::RegisterClassEx(&wcex))
  1515. {
  1516. ::MessageBox( NULL, TEXT("Unable to register Main Window"), TEXT("PLUGTEST"), 0 );
  1517. return(false);
  1518. }
  1519. return(true);
  1520. }
  1521. return(true);
  1522. }
  1523. static HWND Create( DWORD dwExStyle,
  1524. LPCTSTR lpWindowName,
  1525. DWORD dwStyle,
  1526. int x,
  1527. int y,
  1528. int nWidth,
  1529. int nHeight,
  1530. HWND hWndParent,
  1531. HMENU hMenu,
  1532. HINSTANCE hInstance )
  1533. {
  1534. if (RegisterClass( hInstance, TEXT("TestAcqdWindow") ))
  1535. return(CreateWindowEx( dwExStyle, TEXT("TestAcqdWindow"), lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, NULL ));
  1536. return(NULL);
  1537. }
  1538. LRESULT OnDisplayNewImage( WPARAM, LPARAM lParam )
  1539. {
  1540. LPWSTR pszNewImage = reinterpret_cast<LPWSTR>(lParam);
  1541. if (pszNewImage)
  1542. {
  1543. WIA_TRACE((TEXT("pszNewImage: %ws"), pszNewImage ));
  1544. CComPtr<IStream> pStream;
  1545. HRESULT hr = URLOpenBlockingStream( NULL, pszNewImage, &pStream, 0, NULL );
  1546. if (SUCCEEDED(hr))
  1547. {
  1548. HBITMAP hNewBitmap = NULL;
  1549. hr = CGdiPlusHelper().LoadAndScale( hNewBitmap, pStream, 800, 600, false );
  1550. if (SUCCEEDED(hr))
  1551. {
  1552. DestroyBitmap(false);
  1553. m_hOriginalBitmap = hNewBitmap;
  1554. InvalidateRect( m_hWnd, NULL, FALSE );
  1555. UpdateWindow(m_hWnd);
  1556. }
  1557. else
  1558. {
  1559. WIA_PRINTHRESULT((hr,TEXT("GdiPlusHelper.LoadAndScale failed")));
  1560. }
  1561. }
  1562. else
  1563. {
  1564. WIA_PRINTHRESULT((hr,TEXT("URLOpenBlockingStream failed")));
  1565. }
  1566. delete[] pszNewImage;
  1567. }
  1568. return 0;
  1569. }
  1570. STDMETHODIMP StateVariableChanged( IUPnPService * pus, LPCWSTR pcwszStateVarName, VARIANT vaValue )
  1571. {
  1572. WIA_TRACE((TEXT("StateVariableChanged( %p, %ws, %ws )"), pus, pcwszStateVarName, CWiaDebugDump::GetPrintableValue(vaValue).String() ));
  1573. if (!lstrcmpW(pcwszStateVarName,L"CurrentImageURL"))
  1574. {
  1575. if (VT_BSTR == vaValue.vt)
  1576. {
  1577. if (vaValue.bstrVal)
  1578. {
  1579. LPWSTR pszNewImage = new WCHAR[lstrlenW(vaValue.bstrVal)+1];
  1580. if (pszNewImage)
  1581. {
  1582. lstrcpyW( pszNewImage, vaValue.bstrVal );
  1583. WIA_TRACE((TEXT("pszNewImage: %ws"), pszNewImage ));
  1584. PostMessage( m_hWnd, PWM_DISPLAYNEWIMAGE, 0, reinterpret_cast<LPARAM>(pszNewImage) );
  1585. }
  1586. }
  1587. }
  1588. }
  1589. return S_OK;
  1590. }
  1591. STDMETHODIMP ServiceInstanceDied( IUPnPService* pus )
  1592. {
  1593. return S_OK;
  1594. }
  1595. STDMETHODIMP QueryInterface(const IID& iid, void** ppvObject)
  1596. {
  1597. if ((iid==IID_IUnknown) || (iid==IID_IUPnPServiceCallback))
  1598. {
  1599. *ppvObject = static_cast<LPVOID>(this);
  1600. }
  1601. else
  1602. {
  1603. *ppvObject = NULL;
  1604. return(E_NOINTERFACE);
  1605. }
  1606. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  1607. return(S_OK);
  1608. }
  1609. STDMETHODIMP_(ULONG) AddRef()
  1610. {
  1611. return 1;
  1612. }
  1613. STDMETHODIMP_(ULONG) Release()
  1614. {
  1615. return 1;
  1616. }
  1617. };
  1618. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  1619. {
  1620. WIA_DEBUG_CREATE( hInstance );
  1621. g_hInstance = hInstance;
  1622. HRESULT hr = CoInitialize(NULL);
  1623. INITCOMMONCONTROLSEX icc;
  1624. icc.dwSize = sizeof(icc);
  1625. icc.dwICC = ICC_LISTVIEW_CLASSES | ICC_WIN95_CLASSES |ICC_BAR_CLASSES | ICC_LINK_CLASS;
  1626. InitCommonControlsEx(&icc);
  1627. if (SUCCEEDED(hr))
  1628. {
  1629. HWND hwndMain = CMiscUnitTestWindow::Create( 0,
  1630. TEXT("Random Unit Test Program"),
  1631. WS_OVERLAPPEDWINDOW,
  1632. CW_USEDEFAULT, CW_USEDEFAULT,
  1633. CW_USEDEFAULT, CW_USEDEFAULT,
  1634. NULL,
  1635. LoadMenu( hInstance, MAKEINTRESOURCE(IDR_TESTACQDMENU) ),
  1636. hInstance );
  1637. if (!hwndMain)
  1638. {
  1639. MessageBox(NULL, TEXT("Unable to create plugin test window"), TEXT("TESTACQD"), MB_OK);
  1640. return(FALSE);
  1641. }
  1642. ShowWindow(hwndMain, SW_SHOW);
  1643. UpdateWindow(hwndMain);
  1644. HACCEL hAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE(IDR_TESTACQDACCEL) );
  1645. MSG msg;
  1646. while (GetMessage(&msg, 0, 0, 0))
  1647. {
  1648. if (!TranslateAccelerator( hwndMain, hAccel, &msg ))
  1649. {
  1650. TranslateMessage(&msg);
  1651. DispatchMessage(&msg);
  1652. }
  1653. }
  1654. CoUninitialize();
  1655. }
  1656. WIA_DEBUG_DESTROY();
  1657. return(0);
  1658. }