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.

1566 lines
57 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SCANDLG.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 10/7/1999
  12. *
  13. * DESCRIPTION: Scan Dialog Implementation
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "uiexthlp.h"
  19. #include "simrect.h"
  20. #include "movewnd.h"
  21. #include "dlgunits.h"
  22. #include "wiaregst.h"
  23. #include "gwiaevnt.h"
  24. #include "wiacsh.h"
  25. //
  26. // Context Help IDs
  27. //
  28. static const DWORD g_HelpIDs[] =
  29. {
  30. IDC_LARGE_TITLE, -1,
  31. IDC_SCANDLG_SELECT_PROMPT, -1,
  32. IDC_INTENT_ICON_1, IDH_WIA_PIC_TYPE,
  33. IDC_INTENT_ICON_2, IDH_WIA_PIC_TYPE,
  34. IDC_INTENT_ICON_3, IDH_WIA_PIC_TYPE,
  35. IDC_INTENT_ICON_4, IDH_WIA_PIC_TYPE,
  36. IDC_INTENT_1, IDH_WIA_PIC_TYPE,
  37. IDC_INTENT_2, IDH_WIA_PIC_TYPE,
  38. IDC_INTENT_3, IDH_WIA_PIC_TYPE,
  39. IDC_INTENT_4, IDH_WIA_PIC_TYPE,
  40. IDC_SCANDLG_PAPERSOURCE, IDH_WIA_PAPER_SOURCE,
  41. IDC_SCANDLG_PAPERSIZE, IDH_WIA_PAGE_SIZE,
  42. IDC_SCANDLG_RESCAN, IDH_WIA_PREVIEW_BUTTON,
  43. IDC_SCANDLG_SCAN, IDH_WIA_SCAN_BUTTON,
  44. IDC_SCANDLG_PREVIEW, IDH_WIA_IMAGE_PREVIEW,
  45. IDC_INNER_PREVIEW_WINDOW, IDH_WIA_IMAGE_PREVIEW,
  46. IDC_YOU_CAN_ALSO, IDH_WIA_CUSTOM_SETTINGS,
  47. IDC_SCANDLG_ADVANCED, IDH_WIA_CUSTOM_SETTINGS,
  48. IDCANCEL, IDH_CANCEL,
  49. 0, 0
  50. };
  51. #define REGSTR_PATH_USER_SETTINGS_SCANDLG REGSTR_PATH_USER_SETTINGS TEXT("\\WiaCommonScannerDialog")
  52. #define REGSTR_KEYNAME_USER_SETTINGS_SCANDLG TEXT("CommonDialogCustomSettings")
  53. extern HINSTANCE g_hInstance;
  54. #define IDC_SIZEBOX 1212
  55. #define PWM_WIAEVENT (WM_USER+1)
  56. //
  57. // Associate a document handling flag with a string resource
  58. //
  59. static const struct
  60. {
  61. int nFlag;
  62. int nStringId;
  63. }
  64. g_SupportedDocumentHandlingTypes[] =
  65. {
  66. { FLATBED, IDS_SCANDLG_FLATBED },
  67. { FEEDER, IDS_SCANDLG_ADF }
  68. };
  69. //
  70. // Associate an icon control's resource id with a radio button's resource id
  71. //
  72. static const struct
  73. {
  74. int nIconId;
  75. int nRadioId;
  76. }
  77. g_IntentRadioButtonIconPairs[] =
  78. {
  79. { IDC_INTENT_ICON_1, IDC_INTENT_1},
  80. { IDC_INTENT_ICON_2, IDC_INTENT_2},
  81. { IDC_INTENT_ICON_3, IDC_INTENT_3},
  82. { IDC_INTENT_ICON_4, IDC_INTENT_4}
  83. };
  84. static const int gs_nCountIntentRadioButtonIconPairs = ARRAYSIZE(g_IntentRadioButtonIconPairs);
  85. /*
  86. * Sole constructor
  87. */
  88. CScannerAcquireDialog::CScannerAcquireDialog( HWND hwnd )
  89. : m_hWnd(hwnd),
  90. m_pDeviceDialogData(NULL),
  91. m_nMsgScanBegin(RegisterWindowMessage(SCAN_NOTIFYBEGINSCAN)),
  92. m_nMsgScanEnd(RegisterWindowMessage(SCAN_NOTIFYENDSCAN)),
  93. m_nMsgScanProgress(RegisterWindowMessage(SCAN_NOTIFYPROGRESS)),
  94. m_bScanning(false),
  95. m_hBigTitleFont(NULL),
  96. m_hIconLarge(NULL),
  97. m_hIconSmall(NULL),
  98. m_bHasFlatBed(false),
  99. m_bHasDocFeed(false),
  100. m_pScannerItem(NULL),
  101. m_hBitmapDefaultPreviewBitmap(NULL)
  102. {
  103. ZeroMemory( &m_sizeDocfeed, sizeof(m_sizeDocfeed) );
  104. ZeroMemory( &m_sizeFlatbed, sizeof(m_sizeFlatbed) );
  105. }
  106. /*
  107. * Destructor
  108. */
  109. CScannerAcquireDialog::~CScannerAcquireDialog(void)
  110. {
  111. //
  112. // Free resources
  113. //
  114. if (m_hBigTitleFont)
  115. {
  116. DeleteObject(m_hBigTitleFont);
  117. m_hBigTitleFont = NULL;
  118. }
  119. if (m_hIconLarge)
  120. {
  121. DestroyIcon(m_hIconLarge);
  122. m_hIconLarge = NULL;
  123. }
  124. if (m_hIconSmall)
  125. {
  126. DestroyIcon(m_hIconSmall);
  127. m_hIconSmall = NULL;
  128. }
  129. if (m_hBitmapDefaultPreviewBitmap)
  130. {
  131. DeleteObject(m_hBitmapDefaultPreviewBitmap);
  132. m_hBitmapDefaultPreviewBitmap = NULL;
  133. }
  134. //
  135. // Free the paper sizes
  136. //
  137. if (m_pPaperSizes)
  138. {
  139. CComPtr<IWiaScannerPaperSizes> pWiaScannerPaperSizes;
  140. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaScannerPaperSizes, (void**)&pWiaScannerPaperSizes );
  141. if (SUCCEEDED(hr))
  142. {
  143. hr = pWiaScannerPaperSizes->FreePaperSizes( &m_pPaperSizes, &m_nPaperSizeCount );
  144. }
  145. }
  146. }
  147. LRESULT CScannerAcquireDialog::OnSize( WPARAM wParam, LPARAM lParam )
  148. {
  149. if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
  150. {
  151. CSimpleRect rcClient( m_hWnd, CSimpleRect::ClientRect );
  152. CDialogUnits dialogUnits(m_hWnd);
  153. CMoveWindow mw;
  154. //
  155. // Get the button rects
  156. //
  157. CSimpleRect rcPreviewButton( GetDlgItem( m_hWnd, IDC_SCANDLG_RESCAN ), CSimpleRect::WindowRect );
  158. CSimpleRect rcScanButton( GetDlgItem( m_hWnd, IDC_SCANDLG_SCAN ), CSimpleRect::WindowRect );
  159. CSimpleRect rcCancelButton( GetDlgItem( m_hWnd, IDCANCEL ), CSimpleRect::WindowRect );
  160. //
  161. // We need to find the left hand side of the preview control
  162. //
  163. CSimpleRect rcPreview( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), CSimpleRect::WindowRect );
  164. rcPreview.ScreenToClient(m_hWnd).left;
  165. //
  166. // Move the preview control
  167. //
  168. mw.Size( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ),
  169. rcClient.Width() - rcPreview.ScreenToClient(m_hWnd).left - dialogUnits.X(7),
  170. rcClient.Height() - dialogUnits.Y(7) - dialogUnits.Y(7) - dialogUnits.Y(7) - rcPreviewButton.Height() );
  171. //
  172. // Move the buttons
  173. //
  174. mw.Move( GetDlgItem( m_hWnd, IDC_SCANDLG_RESCAN ),
  175. rcClient.Width() - dialogUnits.X(7) - rcPreviewButton.Width() - rcScanButton.Width() - rcCancelButton.Width() - dialogUnits.X(8),
  176. rcClient.Height() - rcPreviewButton.Height() - dialogUnits.Y(7) );
  177. mw.Move( GetDlgItem( m_hWnd, IDC_SCANDLG_SCAN ),
  178. rcClient.Width() - dialogUnits.X(7) - rcScanButton.Width() - rcCancelButton.Width() - dialogUnits.X(4),
  179. rcClient.Height() - rcPreviewButton.Height() - dialogUnits.Y(7) );
  180. mw.Move( GetDlgItem( m_hWnd, IDCANCEL ),
  181. rcClient.Width() - dialogUnits.X(7) - rcCancelButton.Width(),
  182. rcClient.Height() - rcPreviewButton.Height() - dialogUnits.Y(7) );
  183. //
  184. // Move the resizing handle
  185. //
  186. mw.Move( GetDlgItem( m_hWnd, IDC_SIZEBOX ),
  187. rcClient.Width() - GetSystemMetrics(SM_CXVSCROLL),
  188. rcClient.Height() - GetSystemMetrics(SM_CYHSCROLL)
  189. );
  190. }
  191. return(0);
  192. }
  193. LRESULT CScannerAcquireDialog::OnInitDialog( WPARAM, LPARAM lParam )
  194. {
  195. //
  196. // Validate the creation parameters
  197. //
  198. m_pDeviceDialogData = reinterpret_cast<DEVICEDIALOGDATA*>(lParam);
  199. if (!m_pDeviceDialogData)
  200. {
  201. WIA_ERROR((TEXT("SCANDLG: Invalid parameter: DEVICEDIALOGDATA*")));
  202. EndDialog( m_hWnd, E_INVALIDARG );
  203. return(0);
  204. }
  205. if (m_pDeviceDialogData->cbSize != sizeof(DEVICEDIALOGDATA))
  206. {
  207. WIA_ERROR((TEXT("SCANDLG: Invalid parameter: DEVICEDIALOGDATA*/PROPSHEETPAGE* (no known sizeof matches lParam)")));
  208. EndDialog( m_hWnd, E_INVALIDARG );
  209. return(0);
  210. }
  211. //
  212. // Initialialize our return stuff
  213. //
  214. m_pDeviceDialogData->lItemCount = 0;
  215. if (m_pDeviceDialogData->ppWiaItems)
  216. {
  217. *m_pDeviceDialogData->ppWiaItems = NULL;
  218. }
  219. //
  220. // Make sure we have valid a valid device
  221. //
  222. if (!m_pDeviceDialogData->pIWiaItemRoot)
  223. {
  224. WIA_ERROR((TEXT("SCANDLG: Invalid paramaters: pIWiaItem")));
  225. EndDialog( m_hWnd, E_INVALIDARG );
  226. return(0);
  227. }
  228. //
  229. // Find all of the scanner items
  230. //
  231. HRESULT hr = m_ScanItemList.Enumerate( m_pDeviceDialogData->pIWiaItemRoot );
  232. if (FAILED(hr))
  233. {
  234. WIA_PRINTHRESULT((hr,TEXT("SCANDLG: m_ScanItemList.Enumerate failed")));
  235. EndDialog( m_hWnd, hr );
  236. return(0);
  237. }
  238. //
  239. // Get the first child item and save it.
  240. //
  241. CScanItemList::Iterator CurItem = m_ScanItemList.CurrentItem();
  242. if (CurItem == m_ScanItemList.End())
  243. {
  244. hr = E_FAIL;
  245. EndDialog( m_hWnd, hr );
  246. return(0);
  247. }
  248. m_pScannerItem = &(*CurItem);
  249. //
  250. // Make sure we have a valid item
  251. //
  252. hr = WiaUiUtil::VerifyScannerProperties(m_pScannerItem->Item());
  253. if (!SUCCEEDED(hr))
  254. {
  255. hr = E_FAIL;
  256. EndDialog( m_hWnd, hr );
  257. return(0);
  258. }
  259. WIA_TRACE((TEXT("Here is the list of scan items:")));
  260. for (CScanItemList::Iterator x=m_ScanItemList.Begin();x != m_ScanItemList.End();++x)
  261. {
  262. WIA_TRACE((TEXT("x = %p"), (*x).Item() ));
  263. }
  264. //
  265. // Get the page sizes
  266. //
  267. CComPtr<IWiaScannerPaperSizes> pWiaScannerPaperSizes;
  268. hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaScannerPaperSizes, (void**)&pWiaScannerPaperSizes );
  269. if (SUCCEEDED(hr))
  270. {
  271. hr = pWiaScannerPaperSizes->GetPaperSizes( &m_pPaperSizes, &m_nPaperSizeCount );
  272. if (FAILED(hr))
  273. {
  274. EndDialog( m_hWnd, hr );
  275. return 0;
  276. }
  277. }
  278. //
  279. // Create and set the big font
  280. //
  281. m_hBigTitleFont = WiaUiUtil::CreateFontWithPointSizeFromWindow( GetDlgItem(m_hWnd,IDC_LARGE_TITLE), 14, false, false );
  282. if (m_hBigTitleFont)
  283. {
  284. SendDlgItemMessage( m_hWnd, IDC_LARGE_TITLE, WM_SETFONT, reinterpret_cast<WPARAM>(m_hBigTitleFont), MAKELPARAM(TRUE,0));
  285. }
  286. //
  287. // Get the flatbed aspect ratio
  288. //
  289. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_HORIZONTAL_BED_SIZE, m_sizeFlatbed.cx );
  290. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_VERTICAL_BED_SIZE, m_sizeFlatbed.cy );
  291. //
  292. // Get the sheet feeder aspect ratio
  293. //
  294. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE, m_sizeDocfeed.cx );
  295. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_VERTICAL_SHEET_FEED_SIZE, m_sizeDocfeed.cy );
  296. // Get the minimum size of the window
  297. RECT rcWindow;
  298. GetWindowRect( m_hWnd, &rcWindow );
  299. m_sizeMinimumWindowSize.cx = (rcWindow.right - rcWindow.left);
  300. m_sizeMinimumWindowSize.cy = (rcWindow.bottom - rcWindow.top);
  301. //
  302. // Initialize the selection rectangle
  303. //
  304. WiaPreviewControl_ClearSelection( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ) );
  305. //
  306. // Ensure that the aspect ratio is correct
  307. //
  308. WiaPreviewControl_SetDefAspectRatio( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), &m_sizeFlatbed );
  309. //
  310. // Add all of the intents
  311. //
  312. PopulateIntentList();
  313. //
  314. // Set the title of the dialog
  315. //
  316. CSimpleStringWide strwDeviceName;
  317. if (PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DIP_DEV_NAME, strwDeviceName ))
  318. {
  319. CSimpleString().Format( IDS_DIALOG_TITLE, g_hInstance, CSimpleStringConvert::NaturalString(strwDeviceName).String() ).SetWindowText( m_hWnd );
  320. }
  321. //
  322. // Center the window on the client
  323. //
  324. WiaUiUtil::CenterWindow( m_hWnd, m_pDeviceDialogData->hwndParent );
  325. //
  326. // Get the device icons
  327. //
  328. CSimpleStringWide strwDeviceId, strwClassId;
  329. LONG nDeviceType;
  330. if (PropStorageHelpers::GetProperty(m_pDeviceDialogData->pIWiaItemRoot,WIA_DIP_UI_CLSID,strwClassId) &&
  331. PropStorageHelpers::GetProperty(m_pDeviceDialogData->pIWiaItemRoot,WIA_DIP_DEV_ID,strwDeviceId) &&
  332. PropStorageHelpers::GetProperty(m_pDeviceDialogData->pIWiaItemRoot,WIA_DIP_DEV_TYPE,nDeviceType))
  333. {
  334. //
  335. // Get the device icons
  336. //
  337. if (SUCCEEDED(WiaUiExtensionHelper::GetDeviceIcons( CSimpleBStr(strwClassId), nDeviceType, &m_hIconSmall, &m_hIconLarge )))
  338. {
  339. if (m_hIconSmall)
  340. {
  341. SendMessage( m_hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(m_hIconSmall) );
  342. }
  343. if (m_hIconLarge)
  344. {
  345. SendMessage( m_hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(m_hIconLarge) );
  346. }
  347. }
  348. //
  349. // Register for disconnect event
  350. //
  351. CGenericWiaEventHandler::RegisterForWiaEvent( strwDeviceId.String(), WIA_EVENT_DEVICE_DISCONNECTED, &m_DisconnectEvent, m_hWnd, PWM_WIAEVENT );
  352. }
  353. //
  354. // We are only resizeable if we have a preview control
  355. //
  356. if (GetDlgItem(m_hWnd,IDC_SCANDLG_PREVIEW))
  357. {
  358. //
  359. // Create the sizing control
  360. //
  361. (void)CreateWindowEx( 0, TEXT("scrollbar"), TEXT(""),
  362. WS_CHILD|WS_VISIBLE|SBS_SIZEGRIP|WS_CLIPSIBLINGS|SBS_SIZEBOXBOTTOMRIGHTALIGN|SBS_BOTTOMALIGN|WS_GROUP,
  363. CSimpleRect(m_hWnd).Width()-GetSystemMetrics(SM_CXVSCROLL),
  364. CSimpleRect(m_hWnd).Height()-GetSystemMetrics(SM_CYHSCROLL),
  365. GetSystemMetrics(SM_CXVSCROLL),
  366. GetSystemMetrics(SM_CYHSCROLL),
  367. m_hWnd, reinterpret_cast<HMENU>(IDC_SIZEBOX),
  368. g_hInstance, NULL );
  369. }
  370. //
  371. // Set a bitmap, so we can select stuff even if the user doesn't do a preview scan
  372. //
  373. m_hBitmapDefaultPreviewBitmap = reinterpret_cast<HBITMAP>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDB_DEFAULT_BITMAP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_DEFAULTCOLOR ));
  374. if (m_hBitmapDefaultPreviewBitmap)
  375. {
  376. WiaPreviewControl_SetBitmap( GetDlgItem(m_hWnd,IDC_SCANDLG_PREVIEW), TRUE, TRUE, m_hBitmapDefaultPreviewBitmap );
  377. }
  378. //
  379. // If the scanner has document handling, it has an ADF.
  380. //
  381. LONG nDocumentHandlingSelect = 0;
  382. if (PropStorageHelpers::GetPropertyFlags( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, nDocumentHandlingSelect ) && (nDocumentHandlingSelect & FEEDER))
  383. {
  384. m_bHasDocFeed = true;
  385. }
  386. else
  387. {
  388. m_bHasDocFeed = false;
  389. }
  390. //
  391. // If the scanner has a vertical bed size, it has a flatbed
  392. //
  393. LONG nVerticalBedSize = 0;
  394. if (PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_VERTICAL_BED_SIZE, nVerticalBedSize ) && nVerticalBedSize)
  395. {
  396. m_bHasFlatBed = true;
  397. }
  398. else
  399. {
  400. m_bHasFlatBed = false;
  401. }
  402. PopulateDocumentHandling();
  403. PopulatePageSize();
  404. HandlePaperSourceSelChange();
  405. HandlePaperSizeSelChange();
  406. SetForegroundWindow(m_hWnd);
  407. return FALSE;
  408. }
  409. bool CScannerAcquireDialog::ApplyCurrentIntent(void)
  410. {
  411. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::ApplyCurrentIntent"));
  412. CWaitCursor wc;
  413. if (m_pScannerItem)
  414. {
  415. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  416. {
  417. if (SendDlgItemMessage( m_hWnd, g_IntentRadioButtonIconPairs[i].nRadioId, BM_GETCHECK, 0, 0 )==BST_CHECKED)
  418. {
  419. LONG lIntent = static_cast<LONG>(GetWindowLongPtr( GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[i].nRadioId ), GWLP_USERDATA ) );
  420. if (lIntent)
  421. {
  422. //
  423. // This is a normal intent
  424. //
  425. return m_pScannerItem->SetIntent( lIntent );
  426. }
  427. else if (m_pScannerItem->CustomPropertyStream().IsValid()) // This is the "custom" intent
  428. {
  429. //
  430. // This is the custom settings pseudo-intent
  431. //
  432. return (SUCCEEDED(m_pScannerItem->CustomPropertyStream().ApplyToWiaItem( m_pScannerItem->Item())));
  433. }
  434. break;
  435. }
  436. }
  437. }
  438. return false;
  439. }
  440. void CScannerAcquireDialog::PopulateDocumentHandling(void)
  441. {
  442. HWND hWndDocumentHandling = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE );
  443. if (m_bHasDocFeed && hWndDocumentHandling)
  444. {
  445. LONG nDocumentHandlingSelectFlags = 0;
  446. PropStorageHelpers::GetPropertyFlags( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, nDocumentHandlingSelectFlags );
  447. LONG nDocumentHandlingSelect = 0;
  448. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, nDocumentHandlingSelect );
  449. if (!nDocumentHandlingSelectFlags)
  450. {
  451. nDocumentHandlingSelectFlags = FLATBED;
  452. }
  453. if (!nDocumentHandlingSelect)
  454. {
  455. nDocumentHandlingSelect = FLATBED;
  456. }
  457. int nSelectIndex = 0;
  458. for (int i=0;i<ARRAYSIZE(g_SupportedDocumentHandlingTypes);i++)
  459. {
  460. if (nDocumentHandlingSelectFlags & g_SupportedDocumentHandlingTypes[i].nFlag)
  461. {
  462. CSimpleString strDocumentHandlingName( g_SupportedDocumentHandlingTypes[i].nStringId, g_hInstance );
  463. if (strDocumentHandlingName.Length())
  464. {
  465. LRESULT nIndex = SendMessage( hWndDocumentHandling, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(strDocumentHandlingName.String()));
  466. if (nIndex != CB_ERR)
  467. {
  468. SendMessage( hWndDocumentHandling, CB_SETITEMDATA, nIndex, g_SupportedDocumentHandlingTypes[i].nFlag );
  469. if (nDocumentHandlingSelect == g_SupportedDocumentHandlingTypes[i].nFlag)
  470. {
  471. nSelectIndex = (int)nIndex;
  472. }
  473. }
  474. }
  475. }
  476. }
  477. SendMessage( hWndDocumentHandling, CB_SETCURSEL, nSelectIndex, 0 );
  478. //
  479. // Make sure all of the strings fit
  480. //
  481. WiaUiUtil::ModifyComboBoxDropWidth(hWndDocumentHandling);
  482. }
  483. }
  484. void CScannerAcquireDialog::PopulatePageSize(void)
  485. {
  486. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE );
  487. if (m_bHasDocFeed && hWndPaperSize)
  488. {
  489. LONG nWidth=0, nHeight=0;
  490. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_HORIZONTAL_SHEET_FEED_SIZE, nWidth );
  491. PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_VERTICAL_SHEET_FEED_SIZE, nHeight );
  492. //
  493. // Which index will initially be selected?
  494. //
  495. LRESULT nSelectIndex = 0;
  496. //
  497. // Save the largest sheet as our initially selected size
  498. //
  499. __int64 nMaximumArea = 0;
  500. for (UINT i=0;i<m_nPaperSizeCount;i++)
  501. {
  502. //
  503. // If this page will fit in the scanner...
  504. //
  505. if (m_pPaperSizes[i].nWidth <= static_cast<UINT>(nWidth) && m_pPaperSizes[i].nHeight <= static_cast<UINT>(nHeight))
  506. {
  507. //
  508. // Get the string name for this paper size
  509. //
  510. CSimpleString strPaperSizeName( CSimpleStringConvert::NaturalString(CSimpleStringWide(m_pPaperSizes[i].pszName)) );
  511. if (strPaperSizeName.Length())
  512. {
  513. //
  514. // Add the string to the combobox
  515. //
  516. LRESULT nIndex = SendMessage( hWndPaperSize, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(strPaperSizeName.String()));
  517. if (nIndex != CB_ERR)
  518. {
  519. //
  520. // Save the index into our global array
  521. //
  522. SendMessage( hWndPaperSize, CB_SETITEMDATA, nIndex, i );
  523. //
  524. // Check to see if this is the largest page, if it is, save the area and the index
  525. //
  526. if (((__int64)m_pPaperSizes[i].nWidth * m_pPaperSizes[i].nHeight) > nMaximumArea)
  527. {
  528. nMaximumArea = m_pPaperSizes[i].nWidth * m_pPaperSizes[i].nHeight;
  529. nSelectIndex = nIndex;
  530. }
  531. }
  532. }
  533. }
  534. }
  535. //
  536. // Select the default size
  537. //
  538. SendMessage( hWndPaperSize, CB_SETCURSEL, nSelectIndex, 0 );
  539. //
  540. // Make sure all of the strings fit
  541. //
  542. WiaUiUtil::ModifyComboBoxDropWidth(hWndPaperSize);
  543. }
  544. }
  545. // Responds to WM_COMMAND notifications from the radio buttons
  546. void CScannerAcquireDialog::OnIntentChange( WPARAM, LPARAM )
  547. {
  548. }
  549. // Check a particular intent, and apply it to the current item
  550. void CScannerAcquireDialog::SetIntentCheck( LONG nIntent )
  551. {
  552. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  553. {
  554. HWND hWndBtn = GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[i].nRadioId );
  555. if (hWndBtn)
  556. {
  557. // If this intent is the same as the one we've been asked to set, check it
  558. if (static_cast<LONG>(GetWindowLongPtr(hWndBtn,GWLP_USERDATA)) == nIntent)
  559. {
  560. SendMessage( hWndBtn, BM_SETCHECK, BST_CHECKED, 0 );
  561. }
  562. else
  563. {
  564. // Uncheck all others
  565. SendMessage( hWndBtn, BM_SETCHECK, BST_UNCHECKED, 0 );
  566. }
  567. }
  568. }
  569. }
  570. // Set up the intent controls
  571. void CScannerAcquireDialog::PopulateIntentList(void)
  572. {
  573. WIA_PUSHFUNCTION(TEXT("PopulateIntentList"));
  574. //
  575. // We will be hiding any controls that are not used
  576. //
  577. int nCurControlSet = 0;
  578. if (m_pScannerItem)
  579. {
  580. static const struct
  581. {
  582. int nIconId;
  583. int nStringId;
  584. LONG_PTR nIntent;
  585. }
  586. s_Intents[] =
  587. {
  588. { IDI_COLORPHOTO, IDS_INTENT_COLOR_PHOTO_TITLE, WIA_INTENT_IMAGE_TYPE_COLOR},
  589. { IDI_GRAYPHOTO, IDS_INTENT_GRAYSCALE_TITLE, WIA_INTENT_IMAGE_TYPE_GRAYSCALE},
  590. { IDI_TEXT_OR_LINEART, IDS_INTENT_TEXT_TITLE, WIA_INTENT_IMAGE_TYPE_TEXT},
  591. { IDI_CUSTOM, IDS_INTENT_CUSTOM_TITLE, 0}
  592. };
  593. static const int s_nIntents = ARRAYSIZE(s_Intents);
  594. LONG nIntents;
  595. WIA_TRACE((TEXT("Value of the current scanner item: %p"), m_pScannerItem->Item()));
  596. if (PropStorageHelpers::GetPropertyFlags( m_pScannerItem->Item(), WIA_IPS_CUR_INTENT, nIntents ))
  597. {
  598. WIA_TRACE((TEXT("Supported intents for this device: %08X"), nIntents ));
  599. for (int i=0;i<s_nIntents;i++)
  600. {
  601. //
  602. // Make sure it is not the special custom intent, OR it is a supported intent
  603. //
  604. if (!s_Intents[i].nIntent || (nIntents & s_Intents[i].nIntent))
  605. {
  606. //
  607. // Load the intent icon
  608. //
  609. HICON hIcon = reinterpret_cast<HICON>(LoadImage( g_hInstance, MAKEINTRESOURCE(s_Intents[i].nIconId), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR ));
  610. //
  611. // Set the icon for this intent
  612. //
  613. SendDlgItemMessage( m_hWnd, g_IntentRadioButtonIconPairs[nCurControlSet].nIconId, STM_SETICON, reinterpret_cast<WPARAM>(hIcon), 0 );
  614. //
  615. // Set the name of this intent
  616. //
  617. CSimpleString( s_Intents[i].nStringId, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[nCurControlSet].nRadioId ) );
  618. //
  619. // Add in the size intent
  620. //
  621. LONG_PTR nIntent = s_Intents[i].nIntent;
  622. if (nIntent)
  623. {
  624. nIntent |= (WIA_INTENT_SIZE_MASK & m_pDeviceDialogData->lIntent);
  625. }
  626. //
  627. // Save the intent with this item
  628. //
  629. SetWindowLongPtr( GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[nCurControlSet].nRadioId ), GWLP_USERDATA, nIntent );
  630. nCurControlSet++;
  631. }
  632. }
  633. }
  634. else
  635. {
  636. WIA_ERROR((TEXT("Unable to get supported intents!")));
  637. }
  638. //
  639. // Set the default intent to be the first in the list
  640. //
  641. SetIntentCheck(static_cast<LONG>(GetWindowLongPtr(GetDlgItem(m_hWnd, g_IntentRadioButtonIconPairs[0].nRadioId ), GWLP_USERDATA )));
  642. //
  643. // Try to get our persisted settings and set them. If an error occurs, we will get new custom settings.
  644. //
  645. if (!m_pScannerItem->CustomPropertyStream().ReadFromRegistry( m_pScannerItem->Item(), HKEY_CURRENT_USER, REGSTR_PATH_USER_SETTINGS_SCANDLG, REGSTR_KEYNAME_USER_SETTINGS_SCANDLG ) ||
  646. FAILED(m_pScannerItem->CustomPropertyStream().ApplyToWiaItem(m_pScannerItem->Item())))
  647. {
  648. //
  649. // Apply the current intent before getting the new custom intent
  650. //
  651. ApplyCurrentIntent();
  652. //
  653. // Get the default custom property stream
  654. //
  655. m_pScannerItem->CustomPropertyStream().AssignFromWiaItem(m_pScannerItem->Item());
  656. }
  657. }
  658. else
  659. {
  660. WIA_ERROR((TEXT("There doesn't appear to be a scanner item")));
  661. }
  662. //
  663. // Hide the remaining controls
  664. //
  665. for (int i=nCurControlSet;i<gs_nCountIntentRadioButtonIconPairs;i++)
  666. {
  667. ShowWindow( GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[i].nRadioId ), SW_HIDE );
  668. ShowWindow( GetDlgItem( m_hWnd, g_IntentRadioButtonIconPairs[i].nIconId ), SW_HIDE );
  669. }
  670. }
  671. /*
  672. * WM_COMMAND handler that rescans the full bed and replaces the image in the preview window
  673. */
  674. void CScannerAcquireDialog::OnRescan( WPARAM, LPARAM )
  675. {
  676. if (m_pScannerItem)
  677. {
  678. if (!ApplyCurrentIntent())
  679. {
  680. //
  681. // If we can't set the intent, tell the user and return
  682. //
  683. MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  684. return;
  685. }
  686. HANDLE hThread = m_pScannerItem->Scan( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), m_hWnd );
  687. if (hThread)
  688. {
  689. m_bScanning = true;
  690. CloseHandle(hThread);
  691. }
  692. else
  693. {
  694. MessageBox( m_hWnd, CSimpleString( IDS_PREVIEWSCAN_ERROR, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  695. }
  696. }
  697. }
  698. /*
  699. * User pressed the OK (scan) button
  700. */
  701. void CScannerAcquireDialog::OnScan( WPARAM, LPARAM )
  702. {
  703. //
  704. // Assume we'll use the preview window's settings, instead of the page size
  705. //
  706. bool bUsePreviewSettings = true;
  707. HRESULT hr = E_FAIL;
  708. if (m_pScannerItem)
  709. {
  710. if (!ApplyCurrentIntent())
  711. {
  712. //
  713. // If we can't set the intent, tell the user and return
  714. //
  715. MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  716. return;
  717. }
  718. //
  719. // Find out if we're in the ADF capable dialog and if we are in document feeder mode
  720. //
  721. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE );
  722. if (hWndPaperSize)
  723. {
  724. if (InDocFeedMode())
  725. {
  726. //
  727. // Get the selected paper size
  728. //
  729. LRESULT nCurSel = SendMessage( hWndPaperSize, CB_GETCURSEL, 0, 0 );
  730. if (nCurSel != CB_ERR)
  731. {
  732. //
  733. // Which entry in the global table is it?
  734. //
  735. LRESULT nPaperSizeIndex = SendMessage( hWndPaperSize, CB_GETITEMDATA, nCurSel, 0 );
  736. //
  737. // If we have a valid page size
  738. //
  739. if (m_pPaperSizes[nPaperSizeIndex].nWidth && m_pPaperSizes[nPaperSizeIndex].nHeight)
  740. {
  741. //
  742. // We won't be using the preview window
  743. //
  744. bUsePreviewSettings = false;
  745. //
  746. // Assume this is not going to work
  747. //
  748. bool bSucceeded = false;
  749. //
  750. // Assume upper-left registration
  751. //
  752. POINT ptOrigin = { 0, 0 };
  753. SIZE sizeExtent = { m_pPaperSizes[nPaperSizeIndex].nWidth, m_pPaperSizes[nPaperSizeIndex].nHeight };
  754. //
  755. // Get the registration, and shift the coordinates as necessary
  756. //
  757. LONG nSheetFeederRegistration;
  758. if (!PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_SHEET_FEEDER_REGISTRATION, nSheetFeederRegistration ))
  759. {
  760. nSheetFeederRegistration = LEFT_JUSTIFIED;
  761. }
  762. if (nSheetFeederRegistration == CENTERED)
  763. {
  764. ptOrigin.x = (m_sizeDocfeed.cx - sizeExtent.cx) / 2;
  765. }
  766. else if (nSheetFeederRegistration == RIGHT_JUSTIFIED)
  767. {
  768. ptOrigin.x = m_sizeDocfeed.cx - sizeExtent.cx;
  769. }
  770. //
  771. // Get the current resolution, so we can calculate the full-bed resolution in terms of the current DPI
  772. //
  773. LONG nXRes = 0, nYRes = 0;
  774. if (PropStorageHelpers::GetProperty( m_pScannerItem->Item(), WIA_IPS_XRES, nXRes ) &&
  775. PropStorageHelpers::GetProperty( m_pScannerItem->Item(), WIA_IPS_YRES, nYRes ))
  776. {
  777. //
  778. // Make sure these are valid resolution settings
  779. //
  780. if (nXRes && nYRes)
  781. {
  782. //
  783. // Calculate the full bed resolution in the current DPI
  784. //
  785. SIZE sizeFullBedResolution = { 0, 0 };
  786. sizeFullBedResolution.cx = WiaUiUtil::MulDivNoRound( nXRes, m_sizeDocfeed.cx, 1000 );
  787. sizeFullBedResolution.cy = WiaUiUtil::MulDivNoRound( nYRes, m_sizeDocfeed.cy, 1000 );
  788. //
  789. // Make sure these resolution numbers are valid
  790. //
  791. if (sizeFullBedResolution.cx && sizeFullBedResolution.cy)
  792. {
  793. //
  794. // Calculate the origin and extent in terms of the current DPI
  795. //
  796. ptOrigin.x = WiaUiUtil::MulDivNoRound( ptOrigin.x, sizeFullBedResolution.cx, m_sizeDocfeed.cx );
  797. ptOrigin.y = WiaUiUtil::MulDivNoRound( ptOrigin.y, sizeFullBedResolution.cy, m_sizeDocfeed.cy );
  798. sizeExtent.cx = WiaUiUtil::MulDivNoRound( sizeExtent.cx, sizeFullBedResolution.cx, m_sizeDocfeed.cx );
  799. sizeExtent.cy = WiaUiUtil::MulDivNoRound( sizeExtent.cy, sizeFullBedResolution.cy, m_sizeDocfeed.cy );
  800. //
  801. // Write the properties
  802. //
  803. if (PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_XPOS, ptOrigin.x ) &&
  804. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_YPOS, ptOrigin.y ) &&
  805. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_XEXTENT, sizeExtent.cx ) &&
  806. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_YEXTENT, sizeExtent.cy ))
  807. {
  808. //
  809. // Tell the scanner to scan from the ADF and to scan one page only
  810. //
  811. if (PropStorageHelpers::SetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, FEEDER ) &&
  812. PropStorageHelpers::SetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_PAGES, 1 ))
  813. {
  814. //
  815. // Everything seemed to work. This item is ready for transfer.
  816. //
  817. bSucceeded = true;
  818. }
  819. }
  820. }
  821. }
  822. }
  823. if (!bSucceeded)
  824. {
  825. //
  826. // If that icky code above failed, tell the user and return
  827. //
  828. MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  829. return;
  830. }
  831. }
  832. }
  833. }
  834. //
  835. // Else, we are not in document feeder mode
  836. //
  837. else
  838. {
  839. //
  840. // Tell the scanner to scan from the flatbed and and clear the page count
  841. //
  842. if (!PropStorageHelpers::SetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, FLATBED ) ||
  843. !PropStorageHelpers::SetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_PAGES, 0 ))
  844. {
  845. //
  846. // If we can't set the document handling, tell the user and return
  847. //
  848. MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  849. return;
  850. }
  851. }
  852. }
  853. //
  854. // This means we are in sheet feeder mode
  855. //
  856. else if (!GetDlgItem(m_hWnd,IDC_SCANDLG_PREVIEW))
  857. {
  858. //
  859. // Set the origin to 0,0 and the extent to max,0
  860. //
  861. //
  862. // Get the current x resolution, so we can calculate the full-bed width in terms of the current DPI
  863. //
  864. LONG nXRes = 0;
  865. if (PropStorageHelpers::GetProperty( m_pScannerItem->Item(), WIA_IPS_XRES, nXRes ))
  866. {
  867. //
  868. // Make sure this is a valid resolution
  869. //
  870. if (nXRes)
  871. {
  872. //
  873. // Calculate the full bed resolution in the current DPI
  874. //
  875. LONG nWidth = WiaUiUtil::MulDivNoRound( nXRes, m_sizeDocfeed.cx, 1000 );
  876. if (nWidth)
  877. {
  878. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_XPOS, 0 );
  879. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_YPOS, 0 );
  880. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_XEXTENT, nWidth );
  881. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_IPS_YEXTENT, 0 );
  882. bUsePreviewSettings = false;
  883. }
  884. }
  885. }
  886. }
  887. //
  888. // If we are scanning from the flatbed, or using custom page size settings, apply the preview window settings
  889. //
  890. if (bUsePreviewSettings)
  891. {
  892. m_pScannerItem->ApplyCurrentPreviewWindowSettings( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ) );
  893. }
  894. //
  895. // Turn off preview scanning.
  896. //
  897. PropStorageHelpers::SetProperty( m_pScannerItem->Item(), WIA_DPS_PREVIEW, WIA_FINAL_SCAN );
  898. //
  899. // Save the scanner item in the result array and return
  900. //
  901. hr = S_OK;
  902. m_pDeviceDialogData->ppWiaItems = (IWiaItem**)CoTaskMemAlloc( sizeof(IWiaItem*) * 1 );
  903. if (m_pDeviceDialogData->ppWiaItems)
  904. {
  905. m_pScannerItem->CustomPropertyStream().WriteToRegistry( m_pScannerItem->Item(), HKEY_CURRENT_USER, REGSTR_PATH_USER_SETTINGS_SCANDLG, REGSTR_KEYNAME_USER_SETTINGS_SCANDLG );
  906. m_pDeviceDialogData->lItemCount = 1;
  907. m_pDeviceDialogData->ppWiaItems[0] = m_pScannerItem->Item();
  908. m_pDeviceDialogData->ppWiaItems[0]->AddRef();
  909. }
  910. else
  911. {
  912. hr = E_OUTOFMEMORY;
  913. m_pDeviceDialogData->lItemCount = 0;
  914. m_pDeviceDialogData->ppWiaItems = NULL;
  915. }
  916. }
  917. EndDialog(m_hWnd,hr);
  918. }
  919. /*
  920. * User cancelled
  921. */
  922. void CScannerAcquireDialog::OnCancel( WPARAM, LPARAM )
  923. {
  924. if (m_bScanning)
  925. {
  926. if (m_pScannerItem)
  927. {
  928. m_pScannerItem->CancelEvent().Signal();
  929. //
  930. // Issue a cancel io command for this item
  931. //
  932. WiaUiUtil::IssueWiaCancelIO(m_pScannerItem->Item());
  933. }
  934. CSimpleString( IDS_WAIT, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDCANCEL ) );
  935. }
  936. else
  937. {
  938. EndDialog(m_hWnd,S_FALSE);
  939. }
  940. }
  941. void CScannerAcquireDialog::OnPreviewSelChange( WPARAM, LPARAM )
  942. {
  943. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnPreviewSelChange"));
  944. }
  945. void CScannerAcquireDialog::OnAdvanced( WPARAM, LPARAM )
  946. {
  947. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnAdvanced"));
  948. CWaitCursor wc;
  949. if (m_pScannerItem)
  950. {
  951. if (!ApplyCurrentIntent())
  952. {
  953. //
  954. // If we can't set the intent, tell the user and return
  955. //
  956. MessageBox( m_hWnd, CSimpleString( IDS_ERROR_SETTING_PROPS, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  957. return;
  958. }
  959. IWiaItem *pWiaItem = m_pScannerItem->Item();
  960. if (pWiaItem)
  961. {
  962. HRESULT hr = WiaUiUtil::SystemPropertySheet( g_hInstance, m_hWnd, pWiaItem, CSimpleString(IDS_ADVANCEDPROPERTIES, g_hInstance) );
  963. if (S_OK == hr)
  964. {
  965. m_pScannerItem->CustomPropertyStream().AssignFromWiaItem(m_pScannerItem->Item());
  966. if (m_pScannerItem->CustomPropertyStream().IsValid())
  967. {
  968. SetDefaultButton( IDC_SCANDLG_RESCAN, true );
  969. SetIntentCheck(0);
  970. }
  971. else WIA_ERROR((TEXT("Unknown error: m_CustomPropertyStream is not valid")));
  972. }
  973. else if (FAILED(hr))
  974. {
  975. MessageBox( m_hWnd, CSimpleString( IDS_SCANDLG_PROPSHEETERROR, g_hInstance ), CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  976. WIA_PRINTHRESULT((hr,TEXT("SystemPropertySheet failed")));
  977. }
  978. }
  979. else WIA_TRACE((TEXT("pWiaItem is NULL")));
  980. }
  981. else WIA_TRACE((TEXT("No current item")));
  982. }
  983. LRESULT CScannerAcquireDialog::OnGetMinMaxInfo( WPARAM, LPARAM lParam )
  984. {
  985. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnGetMinMaxInfo"));
  986. PMINMAXINFO pMinMaxInfo = reinterpret_cast<PMINMAXINFO>(lParam);
  987. if (pMinMaxInfo)
  988. {
  989. pMinMaxInfo->ptMinTrackSize.x = m_sizeMinimumWindowSize.cx;
  990. pMinMaxInfo->ptMinTrackSize.y = m_sizeMinimumWindowSize.cy;
  991. }
  992. return(0);
  993. }
  994. void CScannerAcquireDialog::SetDefaultButton( int nId, bool bFocus )
  995. {
  996. static const int nButtonIds[] = {IDC_SCANDLG_RESCAN,IDC_SCANDLG_SCAN,IDCANCEL,0};
  997. for (int i=0;nButtonIds[i];i++)
  998. if (nButtonIds[i] != nId)
  999. SendDlgItemMessage( m_hWnd, nButtonIds[i], BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE,0) );
  1000. SendMessage( m_hWnd, DM_SETDEFID, nId, 0 );
  1001. SendDlgItemMessage( m_hWnd, nId, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE,0) );
  1002. if (bFocus)
  1003. SetFocus( GetDlgItem( m_hWnd, nId ) );
  1004. }
  1005. LRESULT CScannerAcquireDialog::OnScanBegin( WPARAM, LPARAM )
  1006. {
  1007. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnScanBegin"));
  1008. SetDefaultButton( IDCANCEL, true );
  1009. CSimpleString( IDS_SCANDLG_INITIALIZING_SCANNER, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ) );
  1010. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_SCAN ), FALSE );
  1011. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_RESCAN ), FALSE );
  1012. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_ADVANCED ), FALSE );
  1013. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), FALSE );
  1014. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_1 ), FALSE );
  1015. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_2 ), FALSE );
  1016. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_3 ), FALSE );
  1017. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_4 ), FALSE );
  1018. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_1 ), FALSE );
  1019. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_2 ), FALSE );
  1020. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_3 ), FALSE );
  1021. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_4 ), FALSE );
  1022. EnableWindow( GetDlgItem( m_hWnd, IDC_YOU_CAN_ALSO ), FALSE );
  1023. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE ), FALSE );
  1024. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE_STATIC ), FALSE );
  1025. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE ), FALSE );
  1026. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE_STATIC ), FALSE );
  1027. return(0);
  1028. }
  1029. LRESULT CScannerAcquireDialog::OnScanEnd( WPARAM wParam, LPARAM )
  1030. {
  1031. CWaitCursor wc;
  1032. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnScanEnd"));
  1033. HRESULT hr = static_cast<HRESULT>(wParam);
  1034. if (SUCCEEDED(hr))
  1035. {
  1036. //
  1037. // Only do the region detection if the user hasn't changed it manually,
  1038. // and only if we are not in document feeder mode.
  1039. //
  1040. if (!InDocFeedMode() && !WiaPreviewControl_GetUserChangedSelection( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW )))
  1041. {
  1042. WiaPreviewControl_DetectRegions( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ) );
  1043. }
  1044. }
  1045. else
  1046. {
  1047. CSimpleString strMessage;
  1048. switch (hr)
  1049. {
  1050. case WIA_ERROR_PAPER_EMPTY:
  1051. strMessage.LoadString( IDS_ERROR_OUTOFPAPER, g_hInstance );
  1052. break;
  1053. default:
  1054. strMessage.LoadString( IDS_PREVIEWSCAN_ERROR, g_hInstance );
  1055. break;
  1056. }
  1057. MessageBox( m_hWnd, strMessage, CSimpleString( IDS_SCANDLG_ERROR_TITLE, g_hInstance ), MB_ICONINFORMATION );
  1058. }
  1059. m_bScanning = false;
  1060. SetWindowText( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TEXT("") );
  1061. WiaPreviewControl_SetProgress( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), FALSE );
  1062. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_SCAN ), TRUE );
  1063. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_RESCAN ), TRUE );
  1064. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_ADVANCED ), TRUE );
  1065. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE );
  1066. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_1 ), TRUE );
  1067. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_2 ), TRUE );
  1068. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_3 ), TRUE );
  1069. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_4 ), TRUE );
  1070. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_1 ), TRUE );
  1071. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_2 ), TRUE );
  1072. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_3 ), TRUE );
  1073. EnableWindow( GetDlgItem( m_hWnd, IDC_INTENT_ICON_4 ), TRUE );
  1074. EnableWindow( GetDlgItem( m_hWnd, IDC_YOU_CAN_ALSO ), TRUE );
  1075. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE ), TRUE );
  1076. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE_STATIC ), TRUE );
  1077. if (InDocFeedMode())
  1078. {
  1079. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE ), TRUE );
  1080. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE_STATIC ), TRUE );
  1081. }
  1082. SetDefaultButton( IDC_SCANDLG_SCAN, true );
  1083. CSimpleString( IDS_CANCEL, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDCANCEL ) );
  1084. return(0);
  1085. }
  1086. LRESULT CScannerAcquireDialog::OnScanProgress( WPARAM wParam, LPARAM )
  1087. {
  1088. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnScanProgress"));
  1089. switch (wParam)
  1090. {
  1091. case SCAN_PROGRESS_CLEAR:
  1092. break;
  1093. case SCAN_PROGRESS_INITIALIZING:
  1094. {
  1095. //
  1096. // Start the warming up animation
  1097. //
  1098. WiaPreviewControl_SetProgress( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE );
  1099. }
  1100. break;
  1101. case SCAN_PROGRESS_SCANNING:
  1102. //
  1103. // End the warming up animation
  1104. //
  1105. WiaPreviewControl_SetProgress( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), FALSE );
  1106. //
  1107. // Set the text that says we are now scanning
  1108. //
  1109. CSimpleString( IDS_SCANDLG_SCANNINGPREVIEW, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ) );
  1110. break;
  1111. case SCAN_PROGRESS_COMPLETE:
  1112. break;
  1113. }
  1114. return(0);
  1115. }
  1116. LRESULT CScannerAcquireDialog::OnEnterSizeMove( WPARAM, LPARAM )
  1117. {
  1118. SendDlgItemMessage( m_hWnd, IDC_SCANDLG_PREVIEW, WM_ENTERSIZEMOVE, 0, 0 );
  1119. return(0);
  1120. }
  1121. LRESULT CScannerAcquireDialog::OnExitSizeMove( WPARAM, LPARAM )
  1122. {
  1123. SendDlgItemMessage( m_hWnd, IDC_SCANDLG_PREVIEW, WM_EXITSIZEMOVE, 0, 0 );
  1124. return(0);
  1125. }
  1126. LRESULT CScannerAcquireDialog::OnWiaEvent( WPARAM, LPARAM lParam )
  1127. {
  1128. WIA_PUSHFUNCTION(TEXT("CCameraAcquireDialog::OnWiaEvent"));
  1129. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  1130. if (pEventMessage)
  1131. {
  1132. if (pEventMessage->EventId() == WIA_EVENT_DEVICE_DISCONNECTED)
  1133. {
  1134. WIA_TRACE((TEXT("Received disconnect event")));
  1135. EndDialog( m_hWnd, WIA_ERROR_OFFLINE );
  1136. }
  1137. delete pEventMessage;
  1138. }
  1139. return HANDLED_EVENT_MESSAGE;
  1140. }
  1141. bool CScannerAcquireDialog::InDocFeedMode(void)
  1142. {
  1143. HWND hWndPaperSource = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE );
  1144. if (hWndPaperSource)
  1145. {
  1146. LRESULT nCurSel = SendMessage( hWndPaperSource, CB_GETCURSEL, 0, 0 );
  1147. if (nCurSel != CB_ERR)
  1148. {
  1149. LRESULT nPaperSource = SendMessage( hWndPaperSource, CB_GETITEMDATA, nCurSel, 0 );
  1150. if (nPaperSource)
  1151. {
  1152. if (nPaperSource & FEEDER)
  1153. {
  1154. return true;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. return false;
  1160. }
  1161. void CScannerAcquireDialog::EnableControl( int nControl, BOOL bEnable )
  1162. {
  1163. HWND hWndControl = GetDlgItem( m_hWnd, nControl );
  1164. if (hWndControl)
  1165. {
  1166. BOOL bEnabled = (IsWindowEnabled( hWndControl ) != FALSE);
  1167. if (bEnable != bEnabled)
  1168. {
  1169. EnableWindow( hWndControl, bEnable );
  1170. }
  1171. }
  1172. }
  1173. void CScannerAcquireDialog::ShowControl( int nControl, BOOL bShow )
  1174. {
  1175. HWND hWndControl = GetDlgItem( m_hWnd, nControl );
  1176. if (hWndControl)
  1177. {
  1178. ShowWindow( hWndControl, bShow ? SW_SHOW : SW_HIDE );
  1179. if (!bShow)
  1180. {
  1181. EnableControl( nControl, FALSE );
  1182. }
  1183. }
  1184. }
  1185. void CScannerAcquireDialog::UpdatePreviewControlState(void)
  1186. {
  1187. //
  1188. // Assume we will be showing the preview control
  1189. //
  1190. BOOL bShowPreview = TRUE;
  1191. //
  1192. // First of all, we know we don't allow preview when we are in the dialog that doesn't support
  1193. // preview
  1194. //
  1195. if (GetWindowLong(m_hWnd,GWL_ID) == IDD_SCAN_NO_PREVIEW)
  1196. {
  1197. bShowPreview = FALSE;
  1198. }
  1199. else
  1200. {
  1201. //
  1202. // If we are in feeder mode, we won't show the preview UNLESS the driver explicitly tells us to do so.
  1203. //
  1204. LONG nCurrentPaperSource = 0;
  1205. if (PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, static_cast<LONG>(nCurrentPaperSource)))
  1206. {
  1207. if (FEEDER & nCurrentPaperSource)
  1208. {
  1209. //
  1210. // Remove the tabstop setting from the preview control if we are in feeder mode
  1211. //
  1212. SetWindowLongPtr( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), GWL_STYLE, GetWindowLongPtr( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), GWL_STYLE ) & ~WS_TABSTOP );
  1213. LONG nShowPreviewControl = WIA_DONT_SHOW_PREVIEW_CONTROL;
  1214. if (PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_SHOW_PREVIEW_CONTROL, static_cast<LONG>(nShowPreviewControl)))
  1215. {
  1216. if (WIA_DONT_SHOW_PREVIEW_CONTROL == nShowPreviewControl)
  1217. {
  1218. bShowPreview = FALSE;
  1219. }
  1220. }
  1221. else
  1222. {
  1223. bShowPreview = FALSE;
  1224. }
  1225. }
  1226. else
  1227. {
  1228. //
  1229. // Add the tabstop setting to the preview control if we are in flatbed mode
  1230. //
  1231. SetWindowLongPtr( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), GWL_STYLE, GetWindowLongPtr( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), GWL_STYLE ) | WS_TABSTOP );
  1232. }
  1233. }
  1234. }
  1235. //
  1236. // Update the preview related controls
  1237. //
  1238. WIA_TRACE((TEXT("bShowPreview = %d"), bShowPreview ));
  1239. if (bShowPreview)
  1240. {
  1241. ShowControl( IDC_SCANDLG_PREVIEW, TRUE );
  1242. ShowControl( IDC_SCANDLG_RESCAN, TRUE );
  1243. EnableControl( IDC_SCANDLG_PREVIEW, TRUE );
  1244. EnableControl( IDC_SCANDLG_RESCAN, TRUE );
  1245. }
  1246. else
  1247. {
  1248. ShowControl( IDC_SCANDLG_PREVIEW, FALSE );
  1249. ShowControl( IDC_SCANDLG_RESCAN, FALSE );
  1250. }
  1251. }
  1252. void CScannerAcquireDialog::HandlePaperSourceSelChange(void)
  1253. {
  1254. HWND hWndPaperSource = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSOURCE );
  1255. if (hWndPaperSource)
  1256. {
  1257. LRESULT nCurSel = SendMessage( hWndPaperSource, CB_GETCURSEL, 0, 0 );
  1258. if (nCurSel != CB_ERR)
  1259. {
  1260. LRESULT nPaperSource = SendMessage( hWndPaperSource, CB_GETITEMDATA, nCurSel, 0 );
  1261. if (nPaperSource)
  1262. {
  1263. PropStorageHelpers::SetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_DOCUMENT_HANDLING_SELECT, static_cast<LONG>(nPaperSource) );
  1264. if (nPaperSource & FLATBED)
  1265. {
  1266. //
  1267. // Adjust the preview control settings for allowing region selection
  1268. //
  1269. WiaPreviewControl_SetDefAspectRatio( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), &m_sizeFlatbed );
  1270. WiaPreviewControl_DisableSelection( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), FALSE );
  1271. WiaPreviewControl_SetBorderStyle( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, PS_DOT, 0 );
  1272. WiaPreviewControl_SetHandleSize( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, 6 );
  1273. //
  1274. // Disable the paper size controls
  1275. //
  1276. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE ), FALSE );
  1277. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE_STATIC ), FALSE );
  1278. }
  1279. else
  1280. {
  1281. //
  1282. // Adjust the preview control settings for displaying paper selection
  1283. //
  1284. WiaPreviewControl_SetDefAspectRatio( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), &m_sizeDocfeed );
  1285. WiaPreviewControl_DisableSelection( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE );
  1286. WiaPreviewControl_SetBorderStyle( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, PS_SOLID, 0 );
  1287. WiaPreviewControl_SetHandleSize( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, 0 );
  1288. //
  1289. // Enable the paper size controls
  1290. //
  1291. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE ), TRUE );
  1292. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE_STATIC ), TRUE );
  1293. //
  1294. // Update the region selection feedback
  1295. //
  1296. HandlePaperSizeSelChange();
  1297. }
  1298. }
  1299. }
  1300. UpdatePreviewControlState();
  1301. }
  1302. }
  1303. void CScannerAcquireDialog::HandlePaperSizeSelChange(void)
  1304. {
  1305. HWND hWndPaperSize = GetDlgItem( m_hWnd, IDC_SCANDLG_PAPERSIZE );
  1306. if (InDocFeedMode() && hWndPaperSize)
  1307. {
  1308. LRESULT nCurSel = SendMessage( hWndPaperSize, CB_GETCURSEL, 0, 0 );
  1309. if (nCurSel != CB_ERR)
  1310. {
  1311. LRESULT nPaperSizeIndex = SendMessage( hWndPaperSize, CB_GETITEMDATA, nCurSel, 0 );
  1312. POINT ptOrigin = { 0, 0 };
  1313. SIZE sizeExtent = { m_pPaperSizes[nPaperSizeIndex].nWidth, m_pPaperSizes[nPaperSizeIndex].nHeight };
  1314. if (!sizeExtent.cx)
  1315. {
  1316. sizeExtent.cx = m_sizeDocfeed.cx;
  1317. }
  1318. if (!sizeExtent.cy)
  1319. {
  1320. sizeExtent.cy = m_sizeDocfeed.cy;
  1321. }
  1322. LONG nSheetFeederRegistration;
  1323. if (!PropStorageHelpers::GetProperty( m_pDeviceDialogData->pIWiaItemRoot, WIA_DPS_SHEET_FEEDER_REGISTRATION, nSheetFeederRegistration ))
  1324. {
  1325. nSheetFeederRegistration = LEFT_JUSTIFIED;
  1326. }
  1327. if (nSheetFeederRegistration == CENTERED)
  1328. {
  1329. ptOrigin.x = (m_sizeDocfeed.cx - sizeExtent.cx) / 2;
  1330. }
  1331. else if (nSheetFeederRegistration == RIGHT_JUSTIFIED)
  1332. {
  1333. ptOrigin.x = m_sizeDocfeed.cx - sizeExtent.cx;
  1334. }
  1335. WiaPreviewControl_SetResolution( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), &m_sizeDocfeed );
  1336. WiaPreviewControl_SetSelOrigin( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), 0, FALSE, &ptOrigin );
  1337. WiaPreviewControl_SetSelExtent( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), 0, FALSE, &sizeExtent );
  1338. }
  1339. }
  1340. }
  1341. void CScannerAcquireDialog::OnPaperSourceSelChange( WPARAM, LPARAM )
  1342. {
  1343. HandlePaperSourceSelChange();
  1344. }
  1345. void CScannerAcquireDialog::OnPaperSizeSelChange( WPARAM, LPARAM )
  1346. {
  1347. HandlePaperSizeSelChange();
  1348. }
  1349. LRESULT CScannerAcquireDialog::OnHelp( WPARAM wParam, LPARAM lParam )
  1350. {
  1351. return WiaHelp::HandleWmHelp( wParam, lParam, g_HelpIDs );
  1352. }
  1353. LRESULT CScannerAcquireDialog::OnContextMenu( WPARAM wParam, LPARAM lParam )
  1354. {
  1355. return WiaHelp::HandleWmContextMenu( wParam, lParam, g_HelpIDs );
  1356. }
  1357. LRESULT CScannerAcquireDialog::OnDestroy( WPARAM, LPARAM )
  1358. {
  1359. for (int i=0;i<gs_nCountIntentRadioButtonIconPairs;i++)
  1360. {
  1361. HICON hIcon = reinterpret_cast<HICON>(SendDlgItemMessage( m_hWnd, g_IntentRadioButtonIconPairs[i].nIconId, STM_SETICON, 0, 0 ));
  1362. if (hIcon)
  1363. {
  1364. DestroyIcon(hIcon);
  1365. }
  1366. }
  1367. return 0;
  1368. }
  1369. LRESULT CScannerAcquireDialog::OnSysColorChange( WPARAM wParam, LPARAM lParam )
  1370. {
  1371. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, TRUE, GetSysColor(COLOR_WINDOW) );
  1372. WiaPreviewControl_SetBkColor( GetDlgItem( m_hWnd, IDC_SCANDLG_PREVIEW ), TRUE, FALSE, GetSysColor(COLOR_WINDOW) );
  1373. SendDlgItemMessage( m_hWnd, IDC_SCANDLG_ADVANCED, WM_SYSCOLORCHANGE, wParam, lParam );
  1374. return 0;
  1375. }
  1376. LRESULT CScannerAcquireDialog::OnCommand( WPARAM wParam, LPARAM lParam )
  1377. {
  1378. WIA_PUSHFUNCTION(TEXT("CScannerAcquireDialog::OnCommand"));
  1379. SC_BEGIN_COMMAND_HANDLERS()
  1380. {
  1381. SC_HANDLE_COMMAND( IDC_SCANDLG_RESCAN, OnRescan );
  1382. SC_HANDLE_COMMAND( IDC_SCANDLG_SCAN, OnScan );
  1383. SC_HANDLE_COMMAND( IDCANCEL, OnCancel );
  1384. SC_HANDLE_COMMAND( IDC_SCANDLG_ADVANCED, OnAdvanced );
  1385. SC_HANDLE_COMMAND( IDC_INTENT_1,OnIntentChange );
  1386. SC_HANDLE_COMMAND( IDC_INTENT_2,OnIntentChange );
  1387. SC_HANDLE_COMMAND( IDC_INTENT_3,OnIntentChange );
  1388. SC_HANDLE_COMMAND( IDC_INTENT_4,OnIntentChange );
  1389. SC_HANDLE_COMMAND_NOTIFY( PWN_SELCHANGE, IDC_SCANDLG_PREVIEW, OnPreviewSelChange );
  1390. SC_HANDLE_COMMAND_NOTIFY( CBN_SELCHANGE, IDC_SCANDLG_PAPERSOURCE, OnPaperSourceSelChange );
  1391. SC_HANDLE_COMMAND_NOTIFY( CBN_SELCHANGE, IDC_SCANDLG_PAPERSIZE, OnPaperSizeSelChange );
  1392. }
  1393. SC_END_COMMAND_HANDLERS();
  1394. }
  1395. INT_PTR CALLBACK CScannerAcquireDialog::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1396. {
  1397. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CScannerAcquireDialog)
  1398. {
  1399. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  1400. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  1401. SC_HANDLE_DIALOG_MESSAGE( WM_SIZE, OnSize );
  1402. SC_HANDLE_DIALOG_MESSAGE( WM_GETMINMAXINFO, OnGetMinMaxInfo );
  1403. SC_HANDLE_DIALOG_MESSAGE( WM_ENTERSIZEMOVE, OnEnterSizeMove );
  1404. SC_HANDLE_DIALOG_MESSAGE( WM_EXITSIZEMOVE, OnExitSizeMove );
  1405. SC_HANDLE_DIALOG_MESSAGE( WM_HELP, OnHelp );
  1406. SC_HANDLE_DIALOG_MESSAGE( WM_CONTEXTMENU, OnContextMenu );
  1407. SC_HANDLE_DIALOG_MESSAGE( WM_DESTROY, OnDestroy );
  1408. SC_HANDLE_DIALOG_MESSAGE( PWM_WIAEVENT, OnWiaEvent );
  1409. SC_HANDLE_DIALOG_MESSAGE( WM_SYSCOLORCHANGE, OnSysColorChange );
  1410. }
  1411. SC_HANDLE_REGISTERED_DIALOG_MESSAGE(m_nMsgScanBegin,OnScanBegin);
  1412. SC_HANDLE_REGISTERED_DIALOG_MESSAGE(m_nMsgScanEnd,OnScanEnd);
  1413. SC_HANDLE_REGISTERED_DIALOG_MESSAGE(m_nMsgScanProgress,OnScanProgress);
  1414. SC_END_DIALOG_MESSAGE_HANDLERS();
  1415. }