Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1702 lines
65 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SCANSEL.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: Scanner region selection (preview) page
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "scansel.h"
  19. #include "simcrack.h"
  20. #include "resource.h"
  21. #include "simstr.h"
  22. #include "mboxex.h"
  23. #include "createtb.h"
  24. #include <vwiaset.h>
  25. #define IDC_SCANSEL_SELECTION_BUTTON_BAR 1100
  26. #define IDC_SCANSEL_SHOW_SELECTION 1200
  27. #define IDC_SCANSEL_SHOW_BED 1201
  28. //
  29. // Associate a document handling flag with a string resource
  30. //
  31. static const struct
  32. {
  33. int nFlag;
  34. int nStringId;
  35. }
  36. g_SupportedDocumentHandlingTypes[] =
  37. {
  38. { FLATBED, IDS_SCANSEL_FLATBED },
  39. { FEEDER, IDS_SCANSEL_ADF }
  40. };
  41. static const int g_SupportedDocumentHandlingTypesCount = ARRAYSIZE(g_SupportedDocumentHandlingTypes);
  42. //
  43. // Associate an icon control's resource id with a radio button's resource id
  44. //
  45. static const struct
  46. {
  47. int nIconId;
  48. int nRadioId;
  49. }
  50. gs_IntentRadioButtonIconPairs[] =
  51. {
  52. { IDC_SCANSEL_ICON_1, IDC_SCANSEL_INTENT_1 },
  53. { IDC_SCANSEL_ICON_2, IDC_SCANSEL_INTENT_2 },
  54. { IDC_SCANSEL_ICON_3, IDC_SCANSEL_INTENT_3 },
  55. { IDC_SCANSEL_ICON_4, IDC_SCANSEL_INTENT_4 }
  56. };
  57. static const int gs_nCountIntentRadioButtonIconPairs = ARRAYSIZE(gs_IntentRadioButtonIconPairs);
  58. //
  59. // Sole constructor
  60. //
  61. CScannerSelectionPage::CScannerSelectionPage( HWND hWnd )
  62. : m_hWnd(hWnd),
  63. m_pControllerWindow(NULL),
  64. m_nThreadNotificationMessage(RegisterWindowMessage(STR_THREAD_NOTIFICATION_MESSAGE)),
  65. m_nWiaEventMessage(RegisterWindowMessage(STR_WIAEVENT_NOTIFICATION_MESSAGE)),
  66. m_hBitmapDefaultPreviewBitmap(NULL),
  67. m_bAllowRegionPreview(false),
  68. m_hwndPreview(NULL),
  69. m_hwndSelectionToolbar(NULL),
  70. m_hwndRescan(NULL),
  71. m_ScannerSelectionButtonBarBitmapInfo( g_hInstance, IDB_SCANSEL_TOOLBAR )
  72. {
  73. ZeroMemory( &m_sizeDocfeed, sizeof(m_sizeDocfeed) );
  74. ZeroMemory( &m_sizeFlatbed, sizeof(m_sizeFlatbed) );
  75. }
  76. //
  77. // Destructor
  78. //
  79. CScannerSelectionPage::~CScannerSelectionPage(void)
  80. {
  81. m_hWnd = NULL;
  82. m_pControllerWindow = NULL;
  83. //
  84. // Free the paper sizes
  85. //
  86. if (m_pPaperSizes)
  87. {
  88. CComPtr<IWiaScannerPaperSizes> pWiaScannerPaperSizes;
  89. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaScannerPaperSizes, (void**)&pWiaScannerPaperSizes );
  90. if (SUCCEEDED(hr))
  91. {
  92. hr = pWiaScannerPaperSizes->FreePaperSizes( &m_pPaperSizes, &m_nPaperSizeCount );
  93. }
  94. }
  95. }
  96. //
  97. // Calculate the maximum scan size using the give DPI
  98. //
  99. static bool GetFullResolution( IWiaItem *pWiaItem, LONG nResX, LONG nResY, LONG &nExtX, LONG &nExtY )
  100. {
  101. WIA_PUSHFUNCTION(TEXT("CScannerItem::GetFullResolution"));
  102. CComPtr<IWiaItem> pRootItem;
  103. if (SUCCEEDED(pWiaItem->GetRootItem(&pRootItem)) && pRootItem)
  104. {
  105. LONG lBedSizeX, lBedSizeY;
  106. if (PropStorageHelpers::GetProperty( pRootItem, WIA_DPS_HORIZONTAL_BED_SIZE, lBedSizeX ) &&
  107. PropStorageHelpers::GetProperty( pRootItem, WIA_DPS_VERTICAL_BED_SIZE, lBedSizeY ))
  108. {
  109. nExtX = WiaUiUtil::MulDivNoRound( nResX, lBedSizeX, 1000 );
  110. nExtY = WiaUiUtil::MulDivNoRound( nResY, lBedSizeY, 1000 );
  111. return(true);
  112. }
  113. }
  114. return(false);
  115. }
  116. //
  117. // Calculate the maximum scan size using the give DPI
  118. //
  119. static bool GetBedAspectRatio( IWiaItem *pWiaItem, LONG &nResX, LONG &nResY )
  120. {
  121. WIA_PUSHFUNCTION(TEXT("CScannerItem::GetFullResolution"));
  122. nResX = nResY = 0;
  123. if (pWiaItem)
  124. {
  125. CComPtr<IWiaItem> pRootItem;
  126. if (SUCCEEDED(pWiaItem->GetRootItem(&pRootItem)) && pRootItem)
  127. {
  128. if (PropStorageHelpers::GetProperty( pRootItem, WIA_DPS_HORIZONTAL_BED_SIZE, nResX ) &&
  129. PropStorageHelpers::GetProperty( pRootItem, WIA_DPS_VERTICAL_BED_SIZE, nResY ))
  130. {
  131. return true;
  132. }
  133. }
  134. }
  135. return(false);
  136. }
  137. bool CScannerSelectionPage::ApplyCurrentPreviewWindowSettings(void)
  138. {
  139. WIA_PUSHFUNCTION(TEXT("CScannerSelectionPage::ApplyCurrentPreviewWindowSettings"));
  140. CWiaItem *pWiaItem = GetActiveScannerItem();
  141. if (pWiaItem)
  142. {
  143. CWiaItem::CScanRegionSettings &ScanRegionSettings = pWiaItem->ScanRegionSettings();
  144. //
  145. // m_hwndPreview will be NULL if the preview control is not active
  146. //
  147. if (m_hwndPreview)
  148. {
  149. //
  150. // Get the current resolution
  151. //
  152. SIZE sizeCurrentResolution;
  153. if (PropStorageHelpers::GetProperty( pWiaItem->WiaItem(), WIA_IPS_XRES, sizeCurrentResolution.cx ) &&
  154. PropStorageHelpers::GetProperty( pWiaItem->WiaItem(), WIA_IPS_YRES, sizeCurrentResolution.cy ))
  155. {
  156. //
  157. // Compute the full page resolution of the item
  158. //
  159. if (GetFullResolution( pWiaItem->WiaItem(), sizeCurrentResolution.cx, sizeCurrentResolution.cy, ScanRegionSettings.sizeResolution.cx, ScanRegionSettings.sizeResolution.cy ))
  160. {
  161. //
  162. // Set the resolution in the preview control
  163. //
  164. WiaPreviewControl_SetResolution( m_hwndPreview, &ScanRegionSettings.sizeResolution );
  165. //
  166. // Save the origin and extents
  167. //
  168. WiaPreviewControl_GetSelOrigin( m_hwndPreview, 0, FALSE, &ScanRegionSettings.ptOrigin );
  169. WiaPreviewControl_GetSelExtent( m_hwndPreview, 0, FALSE, &ScanRegionSettings.sizeExtent );
  170. WIA_TRACE((TEXT("ScanRegionSettings.sizeExtent: (%d,%d)"), ScanRegionSettings.sizeExtent.cx, ScanRegionSettings.sizeExtent.cy ));
  171. //
  172. // Set the origin and extents. We don't set them directly, because they might not be a correct multiple
  173. //
  174. if (CValidWiaSettings::SetNumericPropertyOnBoundary( pWiaItem->WiaItem(), WIA_IPS_XPOS, ScanRegionSettings.ptOrigin.x ))
  175. {
  176. if (CValidWiaSettings::SetNumericPropertyOnBoundary( pWiaItem->WiaItem(), WIA_IPS_YPOS, ScanRegionSettings.ptOrigin.y ))
  177. {
  178. if (CValidWiaSettings::SetNumericPropertyOnBoundary( pWiaItem->WiaItem(), WIA_IPS_XEXTENT, ScanRegionSettings.sizeExtent.cx ))
  179. {
  180. if (CValidWiaSettings::SetNumericPropertyOnBoundary( pWiaItem->WiaItem(), WIA_IPS_YEXTENT, ScanRegionSettings.sizeExtent.cy ))
  181. {
  182. return true;
  183. }
  184. else
  185. {
  186. WIA_ERROR((TEXT("PropStorageHelpers::SetProperty on WIA_IPS_YEXTENT failed")));
  187. }
  188. }
  189. else
  190. {
  191. WIA_ERROR((TEXT("PropStorageHelpers::SetProperty on WIA_IPS_XEXTENT failed")));
  192. }
  193. }
  194. else
  195. {
  196. WIA_ERROR((TEXT("PropStorageHelpers::SetProperty on WIA_IPS_YPOS failed")));
  197. }
  198. }
  199. else
  200. {
  201. WIA_ERROR((TEXT("PropStorageHelpers::SetProperty on WIA_IPS_XPOS failed")));
  202. }
  203. }
  204. }
  205. }
  206. }
  207. return false;
  208. }
  209. //
  210. // PSN_WIZNEXT
  211. //
  212. LRESULT CScannerSelectionPage::OnWizNext( WPARAM, LPARAM )
  213. {
  214. WIA_PUSHFUNCTION(TEXT("CScannerSelectionPage::OnWizNext"));
  215. CWiaItem *pWiaItem = GetActiveScannerItem();
  216. if (pWiaItem)
  217. {
  218. pWiaItem->CustomPropertyStream().WriteToRegistry( pWiaItem->WiaItem(), HKEY_CURRENT_USER, REGSTR_PATH_USER_SETTINGS_WIAACMGR, REGSTR_KEYNAME_USER_SETTINGS_WIAACMGR );
  219. }
  220. //
  221. // Assume we'll use the preview window's settings, instead of the page size
  222. //
  223. bool bUsePreviewSettings = true;
  224. //
  225. // Assume there has been a problem
  226. //
  227. bool bSucceeded = false;
  228. //
  229. // Make sure we have all valid data
  230. //
  231. if (m_pControllerWindow->m_pWiaItemRoot && pWiaItem && pWiaItem->WiaItem())
  232. {
  233. //
  234. // Apply the current intent
  235. //
  236. if (ApplyCurrentIntent())
  237. {
  238. //
  239. // Find out if we're in the ADF capable dialog
  240. //
  241. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSIZE );
  242. if (hWndPaperSize)
  243. {
  244. WIA_TRACE((TEXT("ADF Mode")));
  245. //
  246. // See if we are in document feeder mode
  247. //
  248. if (InDocFeedMode())
  249. {
  250. //
  251. // Get the selected paper size
  252. //
  253. LRESULT nCurSel = SendMessage( hWndPaperSize, CB_GETCURSEL, 0, 0 );
  254. if (CB_ERR != nCurSel)
  255. {
  256. //
  257. // Which entry in the global paper size table is it?
  258. //
  259. LRESULT nPaperSizeIndex = SendMessage( hWndPaperSize, CB_GETITEMDATA, nCurSel, 0 );
  260. if (CB_ERR != nPaperSizeIndex)
  261. {
  262. //
  263. // If we have a valid page size
  264. //
  265. if (m_pPaperSizes[nPaperSizeIndex].nWidth && m_pPaperSizes[nPaperSizeIndex].nHeight)
  266. {
  267. //
  268. // We won't be using the preview window
  269. //
  270. bUsePreviewSettings = false;
  271. //
  272. // Assume upper-left registration
  273. //
  274. POINT ptOrigin = { 0, 0 };
  275. SIZE sizeExtent = { m_pPaperSizes[nPaperSizeIndex].nWidth, m_pPaperSizes[nPaperSizeIndex].nHeight };
  276. //
  277. // Get the registration, and shift the coordinates as necessary
  278. //
  279. LONG nSheetFeederRegistration;
  280. if (!PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_SHEET_FEEDER_REGISTRATION, nSheetFeederRegistration ))
  281. {
  282. nSheetFeederRegistration = LEFT_JUSTIFIED;
  283. }
  284. if (nSheetFeederRegistration == CENTERED)
  285. {
  286. ptOrigin.x = (m_sizeDocfeed.cx - sizeExtent.cx) / 2;
  287. }
  288. else if (nSheetFeederRegistration == RIGHT_JUSTIFIED)
  289. {
  290. ptOrigin.x = m_sizeDocfeed.cx - sizeExtent.cx;
  291. }
  292. //
  293. // Get the current resolution, so we can calculate the full-bed resolution in terms of the current DPI
  294. //
  295. LONG nXRes = 0, nYRes = 0;
  296. if (PropStorageHelpers::GetProperty( pWiaItem->WiaItem(), WIA_IPS_XRES, nXRes ) &&
  297. PropStorageHelpers::GetProperty( pWiaItem->WiaItem(), WIA_IPS_YRES, nYRes ))
  298. {
  299. //
  300. // Make sure these are valid resolution settings
  301. //
  302. if (nXRes && nYRes)
  303. {
  304. //
  305. // Calculate the full bed resolution in the current DPI
  306. //
  307. SIZE sizeFullBedResolution = { 0, 0 };
  308. sizeFullBedResolution.cx = WiaUiUtil::MulDivNoRound( nXRes, m_sizeDocfeed.cx, 1000 );
  309. sizeFullBedResolution.cy = WiaUiUtil::MulDivNoRound( nYRes, m_sizeDocfeed.cy, 1000 );
  310. //
  311. // Make sure these resolution numbers are valid
  312. //
  313. if (sizeFullBedResolution.cx && sizeFullBedResolution.cy)
  314. {
  315. //
  316. // Calculate the origin and extent in terms of the current DPI
  317. //
  318. ptOrigin.x = WiaUiUtil::MulDivNoRound( ptOrigin.x, sizeFullBedResolution.cx, m_sizeDocfeed.cx );
  319. ptOrigin.y = WiaUiUtil::MulDivNoRound( ptOrigin.y, sizeFullBedResolution.cy, m_sizeDocfeed.cy );
  320. sizeExtent.cx = WiaUiUtil::MulDivNoRound( sizeExtent.cx, sizeFullBedResolution.cx, m_sizeDocfeed.cx );
  321. sizeExtent.cy = WiaUiUtil::MulDivNoRound( sizeExtent.cy, sizeFullBedResolution.cy, m_sizeDocfeed.cy );
  322. //
  323. // Write the properties
  324. //
  325. if (PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_XPOS, ptOrigin.x ) &&
  326. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_YPOS, ptOrigin.y ) &&
  327. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_XEXTENT, sizeExtent.cx ) &&
  328. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_YEXTENT, sizeExtent.cy ))
  329. {
  330. //
  331. // Tell the scanner to scan from the ADF and to scan one page only
  332. //
  333. if (PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, FEEDER ) &&
  334. PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_PAGES, 1 ))
  335. {
  336. //
  337. // Everything seemed to work. This item is ready for transfer.
  338. //
  339. bSucceeded = true;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. //
  351. // m_hwndPreview will be NULL if the preview control is not active
  352. //
  353. else if (!m_hwndPreview)
  354. {
  355. WIA_TRACE((TEXT("Scrollfed scanner")));
  356. //
  357. // Set the origin to 0,0 and the extent to max,0
  358. //
  359. //
  360. // Get the current x resolution, so we can calculate the full-bed width in terms of the current DPI
  361. //
  362. LONG nXRes = 0;
  363. if (PropStorageHelpers::GetProperty( pWiaItem->WiaItem(), WIA_IPS_XRES, nXRes ))
  364. {
  365. //
  366. // Make sure this is a valid resolution
  367. //
  368. if (nXRes)
  369. {
  370. //
  371. // Calculate the full bed resolution in the current DPI
  372. //
  373. LONG nWidth = WiaUiUtil::MulDivNoRound( nXRes, m_sizeDocfeed.cx, 1000 );
  374. if (nWidth)
  375. {
  376. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_XPOS, 0 );
  377. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_YPOS, 0 );
  378. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_XEXTENT, nWidth );
  379. PropStorageHelpers::SetProperty( pWiaItem->WiaItem(), WIA_IPS_YEXTENT, 0 );
  380. PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_PAGES, 1 );
  381. bUsePreviewSettings = false;
  382. bSucceeded = true;
  383. }
  384. }
  385. }
  386. }
  387. //
  388. // If we are scanning from the flatbed, apply the preview window settings
  389. //
  390. if (bUsePreviewSettings)
  391. {
  392. //
  393. // Tell the scanner to scan from the flatbed and and clear the page count
  394. //
  395. PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, FLATBED );
  396. PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_PAGES, 0 );
  397. //
  398. // Get the origin and extent from the preview control
  399. //
  400. if (ApplyCurrentPreviewWindowSettings())
  401. {
  402. //
  403. // Everything seemed to work. This item is ready for transfer.
  404. //
  405. bSucceeded = true;
  406. }
  407. }
  408. else
  409. {
  410. //
  411. // Clear the preview bitmap. It won't be doing us any good anyway.
  412. //
  413. pWiaItem->BitmapImage(NULL);
  414. }
  415. }
  416. }
  417. if (!bSucceeded)
  418. {
  419. //
  420. // If that icky code above failed, tell the user and let them try again
  421. //
  422. CMessageBoxEx::MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_ICONINFORMATION );
  423. return -1;
  424. }
  425. return 0;
  426. }
  427. //
  428. // PSN_WIZBACK
  429. //
  430. LRESULT CScannerSelectionPage::OnWizBack( WPARAM, LPARAM )
  431. {
  432. return 0;
  433. }
  434. //
  435. // PSN_SETACTIVE
  436. //
  437. LRESULT CScannerSelectionPage::OnSetActive( WPARAM, LPARAM )
  438. {
  439. //
  440. // Make sure we have a valid controller window
  441. //
  442. if (!m_pControllerWindow)
  443. {
  444. return -1;
  445. }
  446. int nWizButtons = PSWIZB_NEXT;
  447. //
  448. // Only enable "back" if the first page is available
  449. //
  450. if (!m_pControllerWindow->SuppressFirstPage())
  451. {
  452. nWizButtons |= PSWIZB_BACK;
  453. }
  454. //
  455. // Set the buttons
  456. //
  457. PropSheet_SetWizButtons( GetParent(m_hWnd), nWizButtons );
  458. //
  459. // We do want to exit on disconnect if we are on this page
  460. //
  461. m_pControllerWindow->m_OnDisconnect = CAcquisitionManagerControllerWindow::OnDisconnectGotoLastpage|CAcquisitionManagerControllerWindow::OnDisconnectFailDownload|CAcquisitionManagerControllerWindow::OnDisconnectFailUpload|CAcquisitionManagerControllerWindow::OnDisconnectFailDelete;
  462. //
  463. // Make sure the preview related controls accurately reflect the current settings
  464. //
  465. UpdateControlState();
  466. return 0;
  467. }
  468. CWiaItem *CScannerSelectionPage::GetActiveScannerItem(void)
  469. {
  470. // Return (for now) the first image in the list
  471. if (m_pControllerWindow->m_pCurrentScannerItem)
  472. {
  473. return m_pControllerWindow->m_pCurrentScannerItem;
  474. }
  475. return NULL;
  476. }
  477. bool CScannerSelectionPage::InPreviewMode(void)
  478. {
  479. bool bResult = false;
  480. if (m_hwndSelectionToolbar)
  481. {
  482. bResult = (SendMessage(m_hwndSelectionToolbar,TB_GETSTATE,IDC_SCANSEL_SHOW_SELECTION,0) & TBSTATE_CHECKED);
  483. }
  484. return bResult;
  485. }
  486. void CScannerSelectionPage::OnRescan( WPARAM, LPARAM )
  487. {
  488. if (!ApplyCurrentIntent())
  489. {
  490. //
  491. // Tell the user it failed, and to try again
  492. //
  493. CMessageBoxEx::MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_ICONINFORMATION );
  494. return;
  495. }
  496. CWiaItem *pWiaItem = GetActiveScannerItem();
  497. if (pWiaItem)
  498. {
  499. //
  500. // Turn off preview mode and disable all the controls
  501. //
  502. if (m_hwndPreview)
  503. {
  504. WiaPreviewControl_SetPreviewMode( m_hwndPreview, FALSE );
  505. }
  506. EnableControls(FALSE);
  507. //
  508. // Clear the cancel event
  509. //
  510. m_PreviewScanCancelEvent.Reset();
  511. //
  512. // If PerformPreviewScan fails, we won't get any messages, so return all controls to their normal state
  513. //
  514. if (!m_pControllerWindow->PerformPreviewScan( pWiaItem, m_PreviewScanCancelEvent.Event() ))
  515. {
  516. //
  517. // Restore the preview mode and re-enable the controls
  518. //
  519. if (m_hwndPreview && m_hwndSelectionToolbar)
  520. {
  521. WiaPreviewControl_SetPreviewMode( m_hwndPreview, InPreviewMode() );
  522. }
  523. EnableControls(TRUE);
  524. }
  525. }
  526. }
  527. bool CScannerSelectionPage::ApplyCurrentIntent(void)
  528. {
  529. CWaitCursor wc;
  530. CWiaItem *pCurItem = GetActiveScannerItem();
  531. if (pCurItem)
  532. {
  533. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  534. {
  535. if (SendDlgItemMessage( m_hWnd, gs_IntentRadioButtonIconPairs[i].nRadioId, BM_GETCHECK, 0, 0 )==BST_CHECKED)
  536. {
  537. LONG lIntent = static_cast<LONG>(GetWindowLongPtr( GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[i].nRadioId ), GWLP_USERDATA ) );
  538. if (lIntent) // This is a normal intent
  539. {
  540. if (pCurItem->SavedPropertyStream().IsValid())
  541. {
  542. if (!SUCCEEDED(pCurItem->SavedPropertyStream().ApplyToWiaItem( pCurItem->WiaItem())))
  543. {
  544. return false;
  545. }
  546. }
  547. if (PropStorageHelpers::SetProperty( pCurItem->WiaItem(), WIA_IPS_CUR_INTENT, lIntent ) &&
  548. PropStorageHelpers::SetProperty( pCurItem->WiaItem(), WIA_IPS_CUR_INTENT, 0 ))
  549. {
  550. return true;
  551. }
  552. }
  553. else if (pCurItem->CustomPropertyStream().IsValid()) // This is the "custom" intent
  554. {
  555. return(SUCCEEDED(pCurItem->CustomPropertyStream().ApplyToWiaItem(pCurItem->WiaItem())));
  556. }
  557. break;
  558. }
  559. }
  560. }
  561. return false;
  562. }
  563. void CScannerSelectionPage::InitializeIntents(void)
  564. {
  565. static const struct
  566. {
  567. int nIconId;
  568. int nStringId;
  569. LONG_PTR nIntent;
  570. }
  571. s_Intents[] =
  572. {
  573. { IDI_CPHOTO, IDS_SCANSEL_COLORPHOTO, WIA_INTENT_IMAGE_TYPE_COLOR},
  574. { IDI_BWPHOTO, IDS_SCANSEL_BW, WIA_INTENT_IMAGE_TYPE_GRAYSCALE},
  575. { IDI_TEXT, IDS_SCANSEL_TEXT, WIA_INTENT_IMAGE_TYPE_TEXT},
  576. { IDI_CUSTOM, IDS_SCANSEL_CUSTOM, 0}
  577. };
  578. static const int s_nIntents = ARRAYSIZE(s_Intents);
  579. //
  580. // We are going to hide all of the controls we don't use
  581. //
  582. int nCurControlSet = 0;
  583. CWiaItem *pCurItem = GetActiveScannerItem();
  584. if (pCurItem)
  585. {
  586. LONG nIntents;
  587. if (PropStorageHelpers::GetPropertyFlags( pCurItem->WiaItem(), WIA_IPS_CUR_INTENT, nIntents ))
  588. {
  589. for (int i=0;i<s_nIntents;i++)
  590. {
  591. //
  592. // Make sure it is the special custom intent, OR it is a supported intent
  593. //
  594. if (!s_Intents[i].nIntent || (nIntents & s_Intents[i].nIntent))
  595. {
  596. HICON hIcon = reinterpret_cast<HICON>(LoadImage( g_hInstance, MAKEINTRESOURCE(s_Intents[i].nIconId), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR ));
  597. SendDlgItemMessage( m_hWnd, gs_IntentRadioButtonIconPairs[nCurControlSet].nIconId, STM_SETICON, reinterpret_cast<WPARAM>(hIcon), 0 );
  598. CSimpleString( s_Intents[i].nStringId, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[nCurControlSet].nRadioId ) );
  599. //
  600. // Only add the intent if there is one. If we don't add it, it will be 0, signifying that we should use the custom settings
  601. //
  602. if (s_Intents[i].nIntent)
  603. {
  604. //
  605. // Add in the WIA_INTENT_MINIMIZE_SIZE flag, to ensure the size is not too large
  606. //
  607. SetWindowLongPtr( GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[nCurControlSet].nRadioId ), GWLP_USERDATA, (s_Intents[i].nIntent|WIA_INTENT_MINIMIZE_SIZE));
  608. }
  609. nCurControlSet++;
  610. }
  611. }
  612. }
  613. //
  614. // Set the default intent to be the first in the list
  615. //
  616. SetIntentCheck(static_cast<LONG>(GetWindowLongPtr(GetDlgItem(m_hWnd, gs_IntentRadioButtonIconPairs[0].nRadioId ), GWLP_USERDATA )));
  617. //
  618. // Get the saved property stream
  619. //
  620. pCurItem->SavedPropertyStream().AssignFromWiaItem(pCurItem->WiaItem());
  621. //
  622. // Try to get our persisted settings and set them. If an error occurs, we will get new custom settings.
  623. //
  624. if (!pCurItem->CustomPropertyStream().ReadFromRegistry( pCurItem->WiaItem(), HKEY_CURRENT_USER, REGSTR_PATH_USER_SETTINGS_WIAACMGR, REGSTR_KEYNAME_USER_SETTINGS_WIAACMGR ) ||
  625. FAILED(pCurItem->CustomPropertyStream().ApplyToWiaItem(pCurItem->WiaItem())))
  626. {
  627. //
  628. // Apply the current intent before getting the new custom intent
  629. //
  630. ApplyCurrentIntent();
  631. //
  632. // Get the default custom property stream
  633. //
  634. pCurItem->CustomPropertyStream().AssignFromWiaItem(pCurItem->WiaItem());
  635. }
  636. }
  637. //
  638. // Hide the controls we didn't use
  639. //
  640. for (int i=nCurControlSet;i<gs_nCountIntentRadioButtonIconPairs;i++)
  641. {
  642. ShowWindow( GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[i].nRadioId ), SW_HIDE );
  643. ShowWindow( GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[i].nIconId ), SW_HIDE );
  644. }
  645. }
  646. static void MyEnableWindow( HWND hWndControl, BOOL bEnable )
  647. {
  648. if (hWndControl)
  649. {
  650. BOOL bEnabled = (IsWindowEnabled( hWndControl ) != FALSE);
  651. if (bEnable != bEnabled)
  652. {
  653. EnableWindow( hWndControl, bEnable );
  654. }
  655. }
  656. }
  657. void CScannerSelectionPage::EnableControl( int nControl, BOOL bEnable )
  658. {
  659. HWND hWndControl = GetDlgItem( m_hWnd, nControl );
  660. if (hWndControl)
  661. {
  662. BOOL bEnabled = (IsWindowEnabled( hWndControl ) != FALSE);
  663. if (bEnable != bEnabled)
  664. {
  665. EnableWindow( hWndControl, bEnable );
  666. }
  667. }
  668. }
  669. void CScannerSelectionPage::ShowControl( int nControl, BOOL bShow )
  670. {
  671. HWND hWndControl = GetDlgItem( m_hWnd, nControl );
  672. if (hWndControl)
  673. {
  674. ShowWindow( hWndControl, bShow ? SW_SHOW : SW_HIDE );
  675. if (!bShow)
  676. {
  677. EnableControl( nControl, FALSE );
  678. }
  679. }
  680. }
  681. //
  682. // Update the preview-related controls' states
  683. //
  684. void CScannerSelectionPage::UpdateControlState(void)
  685. {
  686. WIA_PUSH_FUNCTION((TEXT("CScannerSelectionPage::UpdateControlState") ));
  687. //
  688. // Assume we will be showing the preview control
  689. //
  690. BOOL bShowPreview = TRUE;
  691. //
  692. // First of all, we know we don't allow preview on scroll-fed scanners
  693. //
  694. if (m_pControllerWindow->m_nScannerType == CAcquisitionManagerControllerWindow::ScannerTypeScrollFed)
  695. {
  696. bShowPreview = FALSE;
  697. }
  698. else
  699. {
  700. //
  701. // If we are in feeder mode, we won't show the preview UNLESS the driver explicitly tells us to do so.
  702. //
  703. LONG nCurrentPaperSource = 0;
  704. if (PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, static_cast<LONG>(nCurrentPaperSource)))
  705. {
  706. if (FEEDER & nCurrentPaperSource)
  707. {
  708. WIA_TRACE((TEXT("FEEDER == nCurrentPaperSource")));
  709. m_bAllowRegionPreview = false;
  710. //
  711. // Remove the tabstop setting from the preview control if we are in feeder mode
  712. //
  713. SetWindowLongPtr( m_hwndPreview, GWL_STYLE, GetWindowLongPtr( m_hwndPreview, GWL_STYLE ) & ~WS_TABSTOP );
  714. LONG nShowPreviewControl = WIA_DONT_SHOW_PREVIEW_CONTROL;
  715. if (PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_SHOW_PREVIEW_CONTROL, static_cast<LONG>(nShowPreviewControl)))
  716. {
  717. WIA_TRACE((TEXT("WIA_DPS_SHOW_PREVIEW_CONTROL = %d"),nShowPreviewControl));
  718. if (WIA_DONT_SHOW_PREVIEW_CONTROL == nShowPreviewControl)
  719. {
  720. bShowPreview = FALSE;
  721. }
  722. }
  723. else
  724. {
  725. WIA_TRACE((TEXT("WIA_DPS_SHOW_PREVIEW_CONTROL was not available")));
  726. bShowPreview = FALSE;
  727. }
  728. }
  729. else
  730. {
  731. //
  732. // Enable preview in flatbed mode
  733. //
  734. m_bAllowRegionPreview = false;
  735. CWiaItem *pWiaItem = GetActiveScannerItem();
  736. if (pWiaItem && pWiaItem->BitmapImage())
  737. {
  738. m_bAllowRegionPreview = true;
  739. }
  740. //
  741. // Add the tabstop setting to the preview control if we are in flatbed mode
  742. //
  743. SetWindowLongPtr( m_hwndPreview, GWL_STYLE, GetWindowLongPtr( m_hwndPreview, GWL_STYLE ) | WS_TABSTOP );
  744. }
  745. }
  746. else
  747. {
  748. WIA_TRACE((TEXT("WIA_DPS_DOCUMENT_HANDLING_SELECT is not available")));
  749. }
  750. }
  751. //
  752. // Update the preview related controls
  753. //
  754. WIA_TRACE((TEXT("bShowPreview = %d"), bShowPreview ));
  755. if (bShowPreview)
  756. {
  757. ShowControl( IDC_SCANSEL_PREVIEW, TRUE );
  758. ShowControl( IDC_SCANSEL_SELECTION_BUTTON_BAR, TRUE );
  759. ShowControl( IDC_SCANSEL_RESCAN, TRUE );
  760. EnableControl( IDC_SCANSEL_PREVIEW, TRUE );
  761. if (m_bAllowRegionPreview)
  762. {
  763. ToolbarHelper::EnableToolbarButton( GetDlgItem( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR ), IDC_SCANSEL_SHOW_SELECTION, true );
  764. ToolbarHelper::EnableToolbarButton( GetDlgItem( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR ), IDC_SCANSEL_SHOW_BED, true );
  765. }
  766. else
  767. {
  768. ToolbarHelper::EnableToolbarButton( GetDlgItem( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR ), IDC_SCANSEL_SHOW_SELECTION, false );
  769. ToolbarHelper::EnableToolbarButton( GetDlgItem( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR ), IDC_SCANSEL_SHOW_BED, false );
  770. }
  771. EnableControl( IDC_SCANSEL_RESCAN, TRUE );
  772. m_hwndPreview = GetDlgItem( m_hWnd, IDC_SCANSEL_PREVIEW );
  773. m_hwndSelectionToolbar = GetDlgItem( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR );
  774. m_hwndRescan = GetDlgItem( m_hWnd, IDC_SCANSEL_RESCAN );
  775. PropSheet_SetHeaderSubTitle( GetParent(m_hWnd), PropSheet_HwndToIndex( GetParent(m_hWnd), m_hWnd ), CSimpleString( IDS_SCANNER_SELECT_SUBTITLE, g_hInstance ).String() );
  776. }
  777. else
  778. {
  779. ShowControl( IDC_SCANSEL_PREVIEW, FALSE );
  780. ShowControl( IDC_SCANSEL_SELECTION_BUTTON_BAR, FALSE );
  781. ShowControl( IDC_SCANSEL_RESCAN, FALSE );
  782. m_hwndPreview = NULL;
  783. m_hwndSelectionToolbar = NULL;
  784. m_hwndRescan = NULL;
  785. PropSheet_SetHeaderSubTitle( GetParent(m_hWnd), PropSheet_HwndToIndex( GetParent(m_hWnd), m_hWnd ), CSimpleString( IDS_SCANNER_SELECT_SUBTITLE_NO_PREVIEW, g_hInstance ).String() );
  786. }
  787. }
  788. LRESULT CScannerSelectionPage::OnInitDialog( WPARAM, LPARAM lParam )
  789. {
  790. //
  791. // Make sure this starts out NULL
  792. //
  793. m_pControllerWindow = NULL;
  794. //
  795. // Get the PROPSHEETPAGE.lParam
  796. //
  797. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  798. if (pPropSheetPage)
  799. {
  800. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  801. if (m_pControllerWindow)
  802. {
  803. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  804. }
  805. }
  806. //
  807. // Bail out
  808. //
  809. if (!m_pControllerWindow)
  810. {
  811. EndDialog(m_hWnd,IDCANCEL);
  812. return -1;
  813. }
  814. //
  815. // Dismiss the progress dialog if it is still up
  816. //
  817. if (m_pControllerWindow->m_pWiaProgressDialog)
  818. {
  819. m_pControllerWindow->m_pWiaProgressDialog->Destroy();
  820. m_pControllerWindow->m_pWiaProgressDialog = NULL;
  821. }
  822. if (m_pControllerWindow->m_pWiaItemRoot)
  823. {
  824. //
  825. // Get the flatbed aspect ratio
  826. //
  827. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_HORIZONTAL_BED_SIZE, m_sizeFlatbed.cx );
  828. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_VERTICAL_BED_SIZE, m_sizeFlatbed.cy );
  829. //
  830. // Get the sheet feeder aspect ratio
  831. //
  832. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE, m_sizeDocfeed.cx );
  833. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_VERTICAL_SHEET_FEED_SIZE, m_sizeDocfeed.cy );
  834. }
  835. UpdateControlState();
  836. if (m_hwndPreview)
  837. {
  838. //
  839. // Set a bitmap, so we can select stuff even if the user doesn't do a preview scan
  840. //
  841. m_hBitmapDefaultPreviewBitmap = reinterpret_cast<HBITMAP>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDB_DEFAULT_SCANNER_BITMAP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTCOLOR ));
  842. if (m_hBitmapDefaultPreviewBitmap)
  843. {
  844. WiaPreviewControl_SetBitmap( m_hwndPreview, TRUE, TRUE, m_hBitmapDefaultPreviewBitmap );
  845. }
  846. //
  847. // Initialize the selection rectangle
  848. //
  849. WiaPreviewControl_ClearSelection( m_hwndPreview );
  850. //
  851. // Ensure that the aspect ratio is correct
  852. //
  853. WiaPreviewControl_SetDefAspectRatio( m_hwndPreview, &m_sizeFlatbed );
  854. }
  855. ToolbarHelper::CButtonDescriptor SelectionButtonDescriptors[] =
  856. {
  857. { 0, IDC_SCANSEL_SHOW_SELECTION, 0, BTNS_BUTTON|BTNS_CHECK, false, NULL, 0 },
  858. { 1, IDC_SCANSEL_SHOW_BED, TBSTATE_CHECKED, BTNS_BUTTON|BTNS_CHECK, false, NULL, 0 }
  859. };
  860. HWND hWndSelectionToolbar = ToolbarHelper::CreateToolbar(
  861. m_hWnd,
  862. GetDlgItem(m_hWnd,IDC_SCANSEL_RESCAN),
  863. GetDlgItem(m_hWnd,IDC_SCANSEL_BUTTON_BAR_GUIDE),
  864. ToolbarHelper::AlignRight|ToolbarHelper::AlignTop,
  865. IDC_SCANSEL_SELECTION_BUTTON_BAR,
  866. m_ScannerSelectionButtonBarBitmapInfo,
  867. SelectionButtonDescriptors,
  868. ARRAYSIZE(SelectionButtonDescriptors) );
  869. //
  870. // Nuke the guide window
  871. //
  872. DestroyWindow( GetDlgItem(m_hWnd,IDC_SCANSEL_BUTTON_BAR_GUIDE) );
  873. //
  874. // Make sure the toolbars are visible
  875. //
  876. ShowWindow( hWndSelectionToolbar, SW_SHOW );
  877. UpdateWindow( hWndSelectionToolbar );
  878. //
  879. // Get the page sizes
  880. //
  881. CComPtr<IWiaScannerPaperSizes> pWiaScannerPaperSizes;
  882. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaScannerPaperSizes, (void**)&pWiaScannerPaperSizes );
  883. if (SUCCEEDED(hr))
  884. {
  885. hr = pWiaScannerPaperSizes->GetPaperSizes( &m_pPaperSizes, &m_nPaperSizeCount );
  886. if (FAILED(hr))
  887. {
  888. EndDialog( m_hWnd, hr );
  889. }
  890. }
  891. //
  892. // Initialize the intent controls, set the initial intent, etc.
  893. //
  894. InitializeIntents();
  895. PopulateDocumentHandling();
  896. PopulatePageSize();
  897. HandlePaperSourceSelChange();
  898. HandlePaperSizeSelChange();
  899. return 0;
  900. }
  901. void CScannerSelectionPage::PopulateDocumentHandling(void)
  902. {
  903. HWND hWndDocumentHandling = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSOURCE );
  904. if (m_pControllerWindow->m_pWiaItemRoot &&
  905. m_pControllerWindow->m_nScannerType == CAcquisitionManagerControllerWindow::ScannerTypeFlatbedAdf &&
  906. hWndDocumentHandling)
  907. {
  908. LONG nDocumentHandlingSelectFlags = 0;
  909. PropStorageHelpers::GetPropertyFlags( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, nDocumentHandlingSelectFlags );
  910. LONG nDocumentHandlingSelect = 0;
  911. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, nDocumentHandlingSelect );
  912. if (!nDocumentHandlingSelectFlags)
  913. {
  914. nDocumentHandlingSelectFlags = FLATBED;
  915. }
  916. if (!nDocumentHandlingSelect)
  917. {
  918. nDocumentHandlingSelect = FLATBED;
  919. }
  920. int nSelectIndex = 0;
  921. for (int i=0;i<g_SupportedDocumentHandlingTypesCount;i++)
  922. {
  923. if (nDocumentHandlingSelectFlags & g_SupportedDocumentHandlingTypes[i].nFlag)
  924. {
  925. CSimpleString strDocumentHandlingName( g_SupportedDocumentHandlingTypes[i].nStringId, g_hInstance );
  926. if (strDocumentHandlingName.Length())
  927. {
  928. LRESULT nIndex = SendMessage( hWndDocumentHandling, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(strDocumentHandlingName.String()));
  929. if (nIndex != CB_ERR)
  930. {
  931. SendMessage( hWndDocumentHandling, CB_SETITEMDATA, nIndex, g_SupportedDocumentHandlingTypes[i].nFlag );
  932. if (nDocumentHandlingSelect == g_SupportedDocumentHandlingTypes[i].nFlag)
  933. {
  934. nSelectIndex = (int)nIndex;
  935. }
  936. }
  937. }
  938. }
  939. }
  940. WIA_TRACE((TEXT("Selecting index %d"), nSelectIndex ));
  941. SendMessage( hWndDocumentHandling, CB_SETCURSEL, nSelectIndex, 0 );
  942. //
  943. // Make sure all of the strings fit
  944. //
  945. WiaUiUtil::ModifyComboBoxDropWidth(hWndDocumentHandling);
  946. }
  947. }
  948. void CScannerSelectionPage::PopulatePageSize(void)
  949. {
  950. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSIZE );
  951. if (m_pControllerWindow->m_pWiaItemRoot &&
  952. m_pControllerWindow->m_nScannerType == CAcquisitionManagerControllerWindow::ScannerTypeFlatbedAdf &&
  953. hWndPaperSize)
  954. {
  955. LONG nWidth=0, nHeight=0;
  956. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE, nWidth );
  957. PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_VERTICAL_SHEET_FEED_SIZE, nHeight );
  958. //
  959. // Which index will initially be selected?
  960. //
  961. LRESULT nSelectIndex = 0;
  962. //
  963. // Save the largest sheet as our initially selected size
  964. //
  965. __int64 nMaximumArea = 0;
  966. for (UINT i=0;i<m_nPaperSizeCount;i++)
  967. {
  968. //
  969. // If this page will fit in the scanner...
  970. //
  971. if (m_pPaperSizes[i].nWidth <= static_cast<UINT>(nWidth) && m_pPaperSizes[i].nHeight <= static_cast<UINT>(nHeight))
  972. {
  973. //
  974. // Get the string name for this paper size
  975. //
  976. CSimpleString strPaperSizeName( CSimpleStringConvert::NaturalString(CSimpleStringWide(m_pPaperSizes[i].pszName)) );
  977. if (strPaperSizeName.Length())
  978. {
  979. //
  980. // Add the string to the combobox
  981. //
  982. LRESULT nIndex = SendMessage( hWndPaperSize, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(strPaperSizeName.String()));
  983. if (nIndex != CB_ERR)
  984. {
  985. //
  986. // Save the index into our global array
  987. //
  988. SendMessage( hWndPaperSize, CB_SETITEMDATA, nIndex, i );
  989. //
  990. // Check to see if this is the largest page, if it is, save the area and the index
  991. //
  992. if (((__int64)m_pPaperSizes[i].nWidth * m_pPaperSizes[i].nHeight) > nMaximumArea)
  993. {
  994. nMaximumArea = m_pPaperSizes[i].nWidth * m_pPaperSizes[i].nHeight;
  995. nSelectIndex = nIndex;
  996. }
  997. }
  998. }
  999. }
  1000. }
  1001. //
  1002. // Select the default size
  1003. //
  1004. SendMessage( hWndPaperSize, CB_SETCURSEL, nSelectIndex, 0 );
  1005. //
  1006. // Make sure all of the strings fit
  1007. //
  1008. WiaUiUtil::ModifyComboBoxDropWidth(hWndPaperSize);
  1009. }
  1010. }
  1011. void CScannerSelectionPage::HandlePaperSourceSelChange(void)
  1012. {
  1013. //
  1014. // Make sure we have a valid root item
  1015. //
  1016. if (m_pControllerWindow->m_pWiaItemRoot)
  1017. {
  1018. //
  1019. // Get the paper source combobox and make sure it exists
  1020. //
  1021. HWND hWndPaperSource = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSOURCE );
  1022. if (hWndPaperSource)
  1023. {
  1024. //
  1025. // Get the currently selected paper source
  1026. //
  1027. LRESULT nCurSel = SendMessage( hWndPaperSource, CB_GETCURSEL, 0, 0 );
  1028. if (nCurSel != CB_ERR)
  1029. {
  1030. //
  1031. // Get the paper source
  1032. //
  1033. LRESULT nPaperSource = SendMessage( hWndPaperSource, CB_GETITEMDATA, nCurSel, 0 );
  1034. if (nPaperSource)
  1035. {
  1036. //
  1037. // Set the paper source on the actual item
  1038. //
  1039. PropStorageHelpers::SetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, static_cast<LONG>(nPaperSource) );
  1040. if (nPaperSource & FLATBED)
  1041. {
  1042. //
  1043. // Make sure all of the preview-related controls are visible and enabled
  1044. //
  1045. UpdateControlState();
  1046. if (m_hwndPreview)
  1047. {
  1048. //
  1049. // Adjust the preview control settings for allowing region selection
  1050. //
  1051. WiaPreviewControl_SetDefAspectRatio( m_hwndPreview, &m_sizeFlatbed );
  1052. WiaPreviewControl_DisableSelection( m_hwndPreview, FALSE );
  1053. WiaPreviewControl_SetBorderStyle( m_hwndPreview, TRUE, PS_DOT, 0 );
  1054. WiaPreviewControl_SetHandleSize( m_hwndPreview, TRUE, 6 );
  1055. }
  1056. //
  1057. // Disable the paper size controls
  1058. //
  1059. EnableControl( IDC_SCANSEL_PAPERSIZE, FALSE );
  1060. EnableControl( IDC_SCANSEL_PAPERSIZE_STATIC, FALSE );
  1061. }
  1062. else
  1063. {
  1064. //
  1065. // Make sure all of the preview-related controls are NOT visible
  1066. //
  1067. UpdateControlState();
  1068. if (m_hwndPreview)
  1069. {
  1070. //
  1071. // Adjust the preview control settings for displaying paper selection
  1072. //
  1073. WiaPreviewControl_SetDefAspectRatio( m_hwndPreview, &m_sizeDocfeed );
  1074. WiaPreviewControl_DisableSelection( m_hwndPreview, TRUE );
  1075. WiaPreviewControl_SetBorderStyle( m_hwndPreview, TRUE, PS_SOLID, 0 );
  1076. WiaPreviewControl_SetHandleSize( m_hwndPreview, TRUE, 0 );
  1077. }
  1078. //
  1079. // Enable the paper size controls
  1080. //
  1081. EnableControl( IDC_SCANSEL_PAPERSIZE, TRUE );
  1082. EnableControl( IDC_SCANSEL_PAPERSIZE_STATIC, TRUE );
  1083. //
  1084. // Update the region selection feedback
  1085. //
  1086. HandlePaperSizeSelChange();
  1087. }
  1088. //
  1089. // Reset the preview selection setting
  1090. //
  1091. WiaPreviewControl_SetPreviewMode( m_hwndPreview, FALSE );
  1092. ToolbarHelper::CheckToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_SELECTION, false );
  1093. ToolbarHelper::CheckToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_BED, true );
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. void CScannerSelectionPage::HandlePaperSizeSelChange(void)
  1100. {
  1101. if (m_pControllerWindow->m_pWiaItemRoot)
  1102. {
  1103. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSIZE );
  1104. if (InDocFeedMode() && hWndPaperSize)
  1105. {
  1106. LRESULT nCurSel = SendMessage( hWndPaperSize, CB_GETCURSEL, 0, 0 );
  1107. if (nCurSel != CB_ERR)
  1108. {
  1109. LRESULT nPaperSizeIndex = SendMessage( hWndPaperSize, CB_GETITEMDATA, nCurSel, 0 );
  1110. POINT ptOrigin = { 0, 0 };
  1111. SIZE sizeExtent = { m_pPaperSizes[nPaperSizeIndex].nWidth, m_pPaperSizes[nPaperSizeIndex].nHeight };
  1112. if (!sizeExtent.cx)
  1113. {
  1114. sizeExtent.cx = m_sizeDocfeed.cx;
  1115. }
  1116. if (!sizeExtent.cy)
  1117. {
  1118. sizeExtent.cy = m_sizeDocfeed.cy;
  1119. }
  1120. LONG nSheetFeederRegistration;
  1121. if (!PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPS_SHEET_FEEDER_REGISTRATION, nSheetFeederRegistration ))
  1122. {
  1123. nSheetFeederRegistration = LEFT_JUSTIFIED;
  1124. }
  1125. if (nSheetFeederRegistration == CENTERED)
  1126. {
  1127. ptOrigin.x = (m_sizeDocfeed.cx - sizeExtent.cx) / 2;
  1128. }
  1129. else if (nSheetFeederRegistration == RIGHT_JUSTIFIED)
  1130. {
  1131. ptOrigin.x = m_sizeDocfeed.cx - sizeExtent.cx;
  1132. }
  1133. if (m_hwndPreview)
  1134. {
  1135. WiaPreviewControl_SetResolution( m_hwndPreview, &m_sizeDocfeed );
  1136. WiaPreviewControl_SetSelOrigin( m_hwndPreview, 0, FALSE, &ptOrigin );
  1137. WiaPreviewControl_SetSelExtent( m_hwndPreview, 0, FALSE, &sizeExtent );
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. void CScannerSelectionPage::OnPaperSourceSelChange( WPARAM, LPARAM )
  1144. {
  1145. HandlePaperSourceSelChange();
  1146. }
  1147. void CScannerSelectionPage::OnPaperSizeSelChange( WPARAM, LPARAM )
  1148. {
  1149. HandlePaperSizeSelChange();
  1150. }
  1151. bool CScannerSelectionPage::InDocFeedMode(void)
  1152. {
  1153. HWND hWndPaperSource = GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSOURCE );
  1154. if (hWndPaperSource)
  1155. {
  1156. LRESULT nCurSel = SendMessage( hWndPaperSource, CB_GETCURSEL, 0, 0 );
  1157. if (nCurSel != CB_ERR)
  1158. {
  1159. LRESULT nPaperSource = SendMessage( hWndPaperSource, CB_GETITEMDATA, nCurSel, 0 );
  1160. if (nPaperSource)
  1161. {
  1162. if (nPaperSource & FEEDER)
  1163. {
  1164. return true;
  1165. }
  1166. }
  1167. }
  1168. }
  1169. return false;
  1170. }
  1171. void CScannerSelectionPage::EnableControls( BOOL bEnable )
  1172. {
  1173. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_INTENT_1 ), bEnable );
  1174. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_INTENT_2 ), bEnable );
  1175. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_INTENT_3 ), bEnable );
  1176. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_INTENT_4 ), bEnable );
  1177. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_PROPERTIES ), bEnable );
  1178. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSOURCE_STATIC ), bEnable );
  1179. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSOURCE ), bEnable );
  1180. if (m_hwndPreview)
  1181. {
  1182. MyEnableWindow( m_hwndPreview, bEnable );
  1183. }
  1184. if (m_hwndRescan)
  1185. {
  1186. MyEnableWindow( m_hwndRescan, bEnable );
  1187. }
  1188. //
  1189. // Only disable/enable this control if we are in document feeder mode
  1190. //
  1191. if (InDocFeedMode())
  1192. {
  1193. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSIZE_STATIC ), bEnable );
  1194. MyEnableWindow( GetDlgItem( m_hWnd, IDC_SCANSEL_PAPERSIZE ), bEnable );
  1195. }
  1196. //
  1197. // Only disable/enable this control if there is an image in it.
  1198. //
  1199. if (m_bAllowRegionPreview && m_hwndSelectionToolbar)
  1200. {
  1201. MyEnableWindow( m_hwndSelectionToolbar, bEnable );
  1202. ToolbarHelper::EnableToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_SELECTION, bEnable != FALSE );
  1203. ToolbarHelper::EnableToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_BED, bEnable != FALSE );
  1204. }
  1205. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) == m_hWnd)
  1206. {
  1207. if (bEnable)
  1208. {
  1209. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_NEXT|PSWIZB_BACK );
  1210. }
  1211. else
  1212. {
  1213. PropSheet_SetWizButtons( GetParent(m_hWnd), 0 );
  1214. }
  1215. }
  1216. }
  1217. void CScannerSelectionPage::OnNotifyScanPreview( UINT nMsg, CThreadNotificationMessage *pThreadNotificationMessage )
  1218. {
  1219. //
  1220. // If we don't have a preview window, we can't do previews
  1221. //
  1222. if (m_hwndPreview)
  1223. {
  1224. CPreviewScanThreadNotifyMessage *pPreviewScanThreadNotifyMessage = dynamic_cast<CPreviewScanThreadNotifyMessage*>(pThreadNotificationMessage);
  1225. if (pPreviewScanThreadNotifyMessage)
  1226. {
  1227. switch (pPreviewScanThreadNotifyMessage->Status())
  1228. {
  1229. case CPreviewScanThreadNotifyMessage::Begin:
  1230. {
  1231. //
  1232. // Erase the old bitmap
  1233. //
  1234. WiaPreviewControl_SetBitmap( m_hwndPreview, TRUE, TRUE, m_hBitmapDefaultPreviewBitmap );
  1235. //
  1236. // Tell the user we are initializing the device
  1237. //
  1238. CSimpleString( IDS_SCANSEL_INITIALIZING_SCANNER, g_hInstance ).SetWindowText( m_hwndPreview );
  1239. //
  1240. // Start the warming up progress bar
  1241. //
  1242. WiaPreviewControl_SetProgress( m_hwndPreview, TRUE );
  1243. //
  1244. // Don't allow zooming the selected region in case there are any problems
  1245. //
  1246. m_bAllowRegionPreview = false;
  1247. }
  1248. break;
  1249. case CPreviewScanThreadNotifyMessage::Update:
  1250. {
  1251. //
  1252. // Update the bitmap
  1253. //
  1254. if (WiaPreviewControl_GetBitmap(m_hwndPreview) && WiaPreviewControl_GetBitmap(m_hwndPreview) != m_hBitmapDefaultPreviewBitmap)
  1255. {
  1256. WiaPreviewControl_RefreshBitmap( m_hwndPreview );
  1257. }
  1258. else
  1259. {
  1260. WiaPreviewControl_SetBitmap( m_hwndPreview, TRUE, TRUE, pPreviewScanThreadNotifyMessage->Bitmap() );
  1261. }
  1262. //
  1263. // Tell the user we are scanning
  1264. //
  1265. CSimpleString( IDS_SCANSEL_SCANNINGPREVIEW, g_hInstance ).SetWindowText( m_hwndPreview );
  1266. //
  1267. // Hide the progress control
  1268. //
  1269. WiaPreviewControl_SetProgress( m_hwndPreview, FALSE );
  1270. }
  1271. break;
  1272. case CPreviewScanThreadNotifyMessage::End:
  1273. {
  1274. WIA_PRINTHRESULT((pPreviewScanThreadNotifyMessage->hr(),TEXT("Handling CPreviewScanThreadNotifyMessage::End")));
  1275. //
  1276. // Set the bitmap in the preview control
  1277. //
  1278. WiaPreviewControl_SetBitmap( m_hwndPreview, TRUE, TRUE, pPreviewScanThreadNotifyMessage->Bitmap() ? pPreviewScanThreadNotifyMessage->Bitmap() : m_hBitmapDefaultPreviewBitmap );
  1279. UpdateWindow( m_hwndPreview );
  1280. //
  1281. // Store the bitmap for later
  1282. //
  1283. CWiaItem *pWiaItem = m_pControllerWindow->m_WiaItemList.Find( pPreviewScanThreadNotifyMessage->Cookie() );
  1284. if (pWiaItem)
  1285. {
  1286. //
  1287. // Set the bitmap, whether it is NULL or not.
  1288. //
  1289. pWiaItem->BitmapImage(pPreviewScanThreadNotifyMessage->Bitmap());
  1290. }
  1291. if (SUCCEEDED(pPreviewScanThreadNotifyMessage->hr()))
  1292. {
  1293. //
  1294. // Only do the region detection if the user hasn't changed it manually,
  1295. // and only if we are not in document feeder mode.
  1296. //
  1297. if (!WiaPreviewControl_GetUserChangedSelection( m_hwndPreview ) && !InDocFeedMode())
  1298. {
  1299. WiaPreviewControl_DetectRegions( m_hwndPreview );
  1300. }
  1301. //
  1302. // Allow the user to zoom the selected region if there is a bitmap
  1303. //
  1304. if (pPreviewScanThreadNotifyMessage->Bitmap())
  1305. {
  1306. m_bAllowRegionPreview = true;
  1307. }
  1308. }
  1309. else if (m_pControllerWindow->m_bDisconnected || WIA_ERROR_OFFLINE == pPreviewScanThreadNotifyMessage->hr())
  1310. {
  1311. //
  1312. // Do nothing.
  1313. //
  1314. }
  1315. else
  1316. {
  1317. //
  1318. // Tell the user something bad happened
  1319. //
  1320. CSimpleString strMessage;
  1321. switch (pPreviewScanThreadNotifyMessage->hr())
  1322. {
  1323. case WIA_ERROR_PAPER_EMPTY:
  1324. strMessage.LoadString( IDS_PREVIEWOUTOFPAPER, g_hInstance );
  1325. break;
  1326. default:
  1327. strMessage.LoadString( IDS_PREVIEWSCAN_ERROR, g_hInstance );
  1328. break;
  1329. }
  1330. CMessageBoxEx::MessageBox( m_hWnd, strMessage, CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_ICONWARNING );
  1331. WIA_PRINTHRESULT((pPreviewScanThreadNotifyMessage->hr(),TEXT("The preview scan FAILED!")));
  1332. }
  1333. //
  1334. // Re-enable all of the controls
  1335. //
  1336. EnableControls(TRUE);
  1337. //
  1338. // Update the preview-related controls
  1339. //
  1340. UpdateControlState();
  1341. //
  1342. // remove the status text
  1343. //
  1344. SetWindowText( m_hwndPreview, TEXT("") );
  1345. //
  1346. // Restore the preview mode
  1347. //
  1348. WiaPreviewControl_SetPreviewMode( m_hwndPreview, InPreviewMode() );
  1349. //
  1350. // Hide the animation
  1351. //
  1352. WiaPreviewControl_SetProgress( m_hwndPreview, FALSE );
  1353. }
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. }
  1359. void CScannerSelectionPage::SetIntentCheck( LONG nIntent )
  1360. {
  1361. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  1362. {
  1363. HWND hWndBtn = GetDlgItem( m_hWnd, gs_IntentRadioButtonIconPairs[i].nRadioId );
  1364. if (hWndBtn)
  1365. {
  1366. // If this intent is the same as the one we've been asked to set, check it
  1367. if (static_cast<LONG>(GetWindowLongPtr(hWndBtn,GWLP_USERDATA)) == nIntent)
  1368. {
  1369. SendMessage( hWndBtn, BM_SETCHECK, BST_CHECKED, 0 );
  1370. }
  1371. else
  1372. {
  1373. // Uncheck all others
  1374. SendMessage( hWndBtn, BM_SETCHECK, BST_UNCHECKED, 0 );
  1375. }
  1376. }
  1377. }
  1378. }
  1379. void CScannerSelectionPage::OnProperties( WPARAM, LPARAM )
  1380. {
  1381. CWaitCursor wc;
  1382. CWiaItem *pCurItem = GetActiveScannerItem();
  1383. if (pCurItem && pCurItem->WiaItem())
  1384. {
  1385. if (!ApplyCurrentIntent())
  1386. {
  1387. //
  1388. // Tell the user it failed, and to try again
  1389. //
  1390. CMessageBoxEx::MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_ICONINFORMATION );
  1391. return;
  1392. }
  1393. HRESULT hr = WiaUiUtil::SystemPropertySheet( g_hInstance, m_hWnd, pCurItem->WiaItem(), CSimpleString(IDS_ADVANCEDPROPERTIES, g_hInstance) );
  1394. if (SUCCEEDED(hr))
  1395. {
  1396. if (S_OK == hr)
  1397. {
  1398. pCurItem->CustomPropertyStream().AssignFromWiaItem(pCurItem->WiaItem());
  1399. if (pCurItem->CustomPropertyStream().IsValid())
  1400. {
  1401. SetIntentCheck(0);
  1402. }
  1403. else WIA_ERROR((TEXT("Unknown error: m_CustomPropertyStream is not valid")));
  1404. }
  1405. else WIA_TRACE((TEXT("User cancelled")));
  1406. }
  1407. else
  1408. {
  1409. CMessageBoxEx::MessageBox( m_hWnd, CSimpleString( IDS_PROPERTY_SHEET_ERROR, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_ICONINFORMATION );
  1410. WIA_PRINTHRESULT((hr,TEXT("SystemPropertySheet failed")));
  1411. }
  1412. }
  1413. else WIA_TRACE((TEXT("No current item")));
  1414. }
  1415. void CScannerSelectionPage::OnPreviewSelection( WPARAM wParam, LPARAM )
  1416. {
  1417. if (m_hwndPreview && m_hwndSelectionToolbar)
  1418. {
  1419. bool bNewPreviewSetting = (LOWORD(wParam) == IDC_SCANSEL_SHOW_SELECTION);
  1420. bool bOldPreviewSetting = WiaPreviewControl_GetPreviewMode( m_hwndPreview ) != FALSE;
  1421. ToolbarHelper::CheckToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_SELECTION, LOWORD(wParam) == IDC_SCANSEL_SHOW_SELECTION );
  1422. ToolbarHelper::CheckToolbarButton( m_hwndSelectionToolbar, IDC_SCANSEL_SHOW_BED, LOWORD(wParam) == IDC_SCANSEL_SHOW_BED );
  1423. if (bNewPreviewSetting != bOldPreviewSetting)
  1424. {
  1425. WiaPreviewControl_SetPreviewMode( m_hwndPreview, LOWORD(wParam) == IDC_SCANSEL_SHOW_SELECTION );
  1426. }
  1427. }
  1428. }
  1429. LRESULT CScannerSelectionPage::OnReset( WPARAM, LPARAM )
  1430. {
  1431. m_PreviewScanCancelEvent.Signal();
  1432. return 0;
  1433. }
  1434. LRESULT CScannerSelectionPage::OnGetToolTipDispInfo( WPARAM wParam, LPARAM lParam )
  1435. {
  1436. TOOLTIPTEXT *pToolTipText = reinterpret_cast<TOOLTIPTEXT*>(lParam);
  1437. if (pToolTipText)
  1438. {
  1439. switch (pToolTipText->hdr.idFrom)
  1440. {
  1441. case IDC_SCANSEL_SHOW_SELECTION:
  1442. pToolTipText->hinst = g_hInstance;
  1443. pToolTipText->lpszText = MAKEINTRESOURCE(IDS_SCANSEL_SHOW_SELECTION);
  1444. break;
  1445. case IDC_SCANSEL_SHOW_BED:
  1446. pToolTipText->hinst = g_hInstance;
  1447. pToolTipText->lpszText = MAKEINTRESOURCE(IDS_SCANSEL_SHOW_BED);
  1448. break;
  1449. }
  1450. }
  1451. return 0;
  1452. }
  1453. LRESULT CScannerSelectionPage::OnCommand( WPARAM wParam, LPARAM lParam )
  1454. {
  1455. SC_BEGIN_COMMAND_HANDLERS()
  1456. {
  1457. SC_HANDLE_COMMAND(IDC_SCANSEL_RESCAN,OnRescan);
  1458. SC_HANDLE_COMMAND(IDC_SCANSEL_PROPERTIES,OnProperties);
  1459. SC_HANDLE_COMMAND(IDC_SCANSEL_SHOW_SELECTION,OnPreviewSelection);
  1460. SC_HANDLE_COMMAND(IDC_SCANSEL_SHOW_BED,OnPreviewSelection);
  1461. SC_HANDLE_COMMAND_NOTIFY( CBN_SELCHANGE, IDC_SCANSEL_PAPERSOURCE, OnPaperSourceSelChange );
  1462. SC_HANDLE_COMMAND_NOTIFY( CBN_SELCHANGE, IDC_SCANSEL_PAPERSIZE, OnPaperSizeSelChange );
  1463. }
  1464. SC_END_COMMAND_HANDLERS();
  1465. }
  1466. LRESULT CScannerSelectionPage::OnNotify( WPARAM wParam, LPARAM lParam )
  1467. {
  1468. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  1469. {
  1470. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZNEXT,OnWizNext);
  1471. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZBACK,OnWizBack);
  1472. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  1473. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_RESET,OnReset);
  1474. SC_HANDLE_NOTIFY_MESSAGE_CODE(TTN_GETDISPINFO,OnGetToolTipDispInfo);
  1475. }
  1476. SC_END_NOTIFY_MESSAGE_HANDLERS();
  1477. }
  1478. LRESULT CScannerSelectionPage::OnThreadNotification( WPARAM wParam, LPARAM lParam )
  1479. {
  1480. WTM_BEGIN_THREAD_NOTIFY_MESSAGE_HANDLERS()
  1481. {
  1482. WTM_HANDLE_NOTIFY_MESSAGE( TQ_SCANPREVIEW, OnNotifyScanPreview );
  1483. }
  1484. WTM_END_THREAD_NOTIFY_MESSAGE_HANDLERS();
  1485. }
  1486. LRESULT CScannerSelectionPage::OnEventNotification( WPARAM, LPARAM lParam )
  1487. {
  1488. WIA_PUSH_FUNCTION((TEXT("CCommonFirstPage::OnEventNotification") ));
  1489. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  1490. if (pEventMessage)
  1491. {
  1492. //
  1493. // Don't delete the message, it is deleted in the controller window
  1494. //
  1495. }
  1496. return 0;
  1497. }
  1498. LRESULT CScannerSelectionPage::OnDestroy( WPARAM, LPARAM )
  1499. {
  1500. //
  1501. // Nuke all of the intent icons we loaded
  1502. //
  1503. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  1504. {
  1505. HICON hIcon = reinterpret_cast<HICON>(SendDlgItemMessage( m_hWnd, gs_IntentRadioButtonIconPairs[i].nIconId, STM_SETICON, 0, 0 ));
  1506. if (hIcon)
  1507. {
  1508. DestroyIcon(hIcon);
  1509. }
  1510. }
  1511. return 0;
  1512. }
  1513. LRESULT CScannerSelectionPage::OnSysColorChange( WPARAM wParam, LPARAM lParam )
  1514. {
  1515. m_ScannerSelectionButtonBarBitmapInfo.ReloadAndReplaceBitmap();
  1516. SendDlgItemMessage( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR, WM_SYSCOLORCHANGE, wParam, lParam );
  1517. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_SCANSEL_PREVIEW ), TRUE, TRUE, GetSysColor(COLOR_WINDOW) );
  1518. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_SCANSEL_PREVIEW ), TRUE, FALSE, GetSysColor(COLOR_WINDOW) );
  1519. return 0;
  1520. }
  1521. LRESULT CScannerSelectionPage::OnThemeChanged( WPARAM wParam, LPARAM lParam )
  1522. {
  1523. SendDlgItemMessage( m_hWnd, IDC_SCANSEL_SELECTION_BUTTON_BAR, WM_THEMECHANGED, wParam, lParam );
  1524. return 0;
  1525. }
  1526. INT_PTR CALLBACK CScannerSelectionPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1527. {
  1528. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CScannerSelectionPage)
  1529. {
  1530. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  1531. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  1532. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  1533. SC_HANDLE_DIALOG_MESSAGE( WM_DESTROY, OnDestroy );
  1534. SC_HANDLE_DIALOG_MESSAGE( WM_SYSCOLORCHANGE, OnSysColorChange );
  1535. SC_HANDLE_DIALOG_MESSAGE( WM_THEMECHANGED, OnThemeChanged );
  1536. }
  1537. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nThreadNotificationMessage, OnThreadNotification );
  1538. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nWiaEventMessage, OnEventNotification );
  1539. SC_END_DIALOG_MESSAGE_HANDLERS();
  1540. }