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.

857 lines
27 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: PPSCAN.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/17/1999
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "ppscan.h"
  19. #include "resource.h"
  20. #include "wiacsh.h"
  21. //
  22. // Context Help IDs
  23. //
  24. static const DWORD g_HelpIDs[] =
  25. {
  26. IDC_SCANPROP_BRIGHTNESS_PROMPT, IDH_WIA_BRIGHTNESS,
  27. IDC_SCANPROP_BRIGHTNESS_SLIDER, IDH_WIA_BRIGHTNESS,
  28. IDC_SCANPROP_BRIGHTNESS_EDIT, IDH_WIA_BRIGHTNESS,
  29. IDC_SCANPROP_CONTRAST_PROMPT, IDH_WIA_CONTRAST,
  30. IDC_SCANPROP_CONTRAST_SLIDER, IDH_WIA_CONTRAST,
  31. IDC_SCANPROP_CONTRAST_EDIT, IDH_WIA_CONTRAST,
  32. IDC_SCANPROP_RESOLUTION_PROMPT, IDH_WIA_PIC_RESOLUTION,
  33. IDC_SCANPROP_RESOLUTION_EDIT, IDH_WIA_PIC_RESOLUTION,
  34. IDC_SCANPROP_RESOLUTION_UPDOWN, IDH_WIA_PIC_RESOLUTION,
  35. IDC_SCANPROP_PREVIEW, IDH_WIA_CUSTOM_PREVIEW,
  36. IDC_SCANPROP_DATATYPE_PROMPT, IDH_WIA_IMAGE_TYPE,
  37. IDC_SCANPROP_DATATYPE_LIST, IDH_WIA_IMAGE_TYPE,
  38. IDC_SCANPROP_RESTOREDEFAULT, IDH_WIA_RESTORE_DEFAULT,
  39. IDOK, IDH_OK,
  40. IDCANCEL, IDH_CANCEL,
  41. 0, 0
  42. };
  43. extern HINSTANCE g_hInstance;
  44. //
  45. // These are the data types we support
  46. //
  47. static struct
  48. {
  49. int nStringId;
  50. LONG nDataType;
  51. UINT nPreviewWindowIntent;
  52. } g_AvailableColorDepths[] =
  53. {
  54. { IDS_SCANPROP_COLOR, WIA_DATA_COLOR, BCPWM_COLOR },
  55. { IDS_SCANPROP_GRAYSCALE, WIA_DATA_GRAYSCALE, BCPWM_GRAYSCALE },
  56. { IDS_SCANPROP_BLACKANDWHITE, WIA_DATA_THRESHOLD, BCPWM_BW }
  57. };
  58. #define AVAILABLE_COLOR_DEPTH_COUNT (sizeof(g_AvailableColorDepths)/sizeof(g_AvailableColorDepths[0]))
  59. //
  60. // If we don't have a good range of values for the brightness and contrast settings,
  61. // we want to disable the preview control. This is the minumum number of values
  62. // we consider useful for this purpose
  63. //
  64. const int CScannerCommonPropertyPage::c_nMinBrightnessAndContrastSettingCount = 10;
  65. //
  66. // The only constructor
  67. //
  68. CScannerCommonPropertyPage::CScannerCommonPropertyPage( HWND hWnd )
  69. : m_hWnd(hWnd),
  70. m_nProgrammaticSetting(0),
  71. m_nControlsInUse(0)
  72. {
  73. }
  74. CScannerCommonPropertyPage::~CScannerCommonPropertyPage(void)
  75. {
  76. m_hWnd = NULL;
  77. }
  78. LRESULT CScannerCommonPropertyPage::OnKillActive( WPARAM , LPARAM )
  79. {
  80. CWaitCursor wc;
  81. if (!ValidateEditControls())
  82. {
  83. return TRUE;
  84. }
  85. ApplySettings();
  86. return FALSE;
  87. }
  88. LRESULT CScannerCommonPropertyPage::OnSetActive( WPARAM , LPARAM )
  89. {
  90. CWaitCursor wc;
  91. Initialize();
  92. return 0;
  93. }
  94. LRESULT CScannerCommonPropertyPage::OnApply( WPARAM , LPARAM )
  95. {
  96. if (ApplySettings())
  97. {
  98. return PSNRET_NOERROR;
  99. }
  100. else
  101. {
  102. //
  103. // Tell the user there was an error
  104. //
  105. MessageBox( m_hWnd,
  106. CSimpleString( IDS_SCANPROP_UNABLETOWRITE, g_hInstance ),
  107. CSimpleString( IDS_SCANPROP_ERROR_TITLE, g_hInstance ),
  108. MB_ICONINFORMATION );
  109. return PSNRET_INVALID_NOCHANGEPAGE;
  110. }
  111. }
  112. void CScannerCommonPropertyPage::SetText( HWND hWnd, LPCTSTR pszText )
  113. {
  114. m_nProgrammaticSetting++;
  115. SetWindowText( hWnd, pszText );
  116. m_nProgrammaticSetting--;
  117. }
  118. void CScannerCommonPropertyPage::SetText( HWND hWnd, LONG nNumber )
  119. {
  120. SetText( hWnd, CSimpleStringConvert::NumberToString( nNumber ) );
  121. }
  122. bool CScannerCommonPropertyPage::PopulateDataTypes(void)
  123. {
  124. //
  125. // We will be successful if we can add at least one data type
  126. //
  127. bool bSuccess = false;
  128. //
  129. // Clear the list
  130. //
  131. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_RESETCONTENT, 0, 0 );
  132. //
  133. // Try to load the data types for this device
  134. //
  135. CSimpleDynamicArray<LONG> SupportedDataTypes;
  136. LONG nCurrentDataType;
  137. if (PropStorageHelpers::GetProperty( m_pIWiaItem, WIA_IPA_DATATYPE, nCurrentDataType ) &&
  138. PropStorageHelpers::GetPropertyList( m_pIWiaItem, WIA_IPA_DATATYPE, SupportedDataTypes ))
  139. {
  140. //
  141. // Loop through each of the data types we handle, and see if it is supported by the device
  142. //
  143. m_nInitialDataTypeSelection = 0;
  144. for (int i=0;i<AVAILABLE_COLOR_DEPTH_COUNT;i++)
  145. {
  146. //
  147. // Is this one of the data types we support?
  148. //
  149. if (SupportedDataTypes.Find(g_AvailableColorDepths[i].nDataType) != -1)
  150. {
  151. //
  152. // Load the data type string and make sure it is valid
  153. //
  154. CSimpleString strDataTypeName( g_AvailableColorDepths[i].nStringId, g_hInstance );
  155. if (strDataTypeName.Length())
  156. {
  157. //
  158. // Add the string to the combo box
  159. //
  160. LRESULT nIndex = SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(strDataTypeName.String()));
  161. if (nIndex != CB_ERR)
  162. {
  163. //
  164. // Save the index of the global data type struct we are using for this entry
  165. //
  166. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_SETITEMDATA, nIndex, i );
  167. //
  168. // Whew, we made it at least once, so we are using this control
  169. //
  170. bSuccess = true;
  171. //
  172. // Save the current selection and update the preview control
  173. //
  174. if (nCurrentDataType == g_AvailableColorDepths[i].nDataType)
  175. {
  176. m_nInitialDataTypeSelection = static_cast<int>(nIndex);
  177. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_SETINTENT, 0, g_AvailableColorDepths[i].nPreviewWindowIntent );
  178. }
  179. }
  180. }
  181. }
  182. }
  183. //
  184. // Set the current selection
  185. //
  186. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_SETCURSEL, m_nInitialDataTypeSelection, 0 );
  187. }
  188. return bSuccess;
  189. }
  190. bool CScannerCommonPropertyPage::IsUselessPreviewRange( const CValidWiaSettings &Settings )
  191. {
  192. return (Settings.GetItemCount() < c_nMinBrightnessAndContrastSettingCount);
  193. }
  194. void CScannerCommonPropertyPage::Initialize()
  195. {
  196. //
  197. // Make sure we don't get into an infinite loop
  198. //
  199. m_nProgrammaticSetting++;
  200. //
  201. // Assume we aren't using any controls at all
  202. //
  203. m_nControlsInUse = 0;
  204. //
  205. // Get the valid settings for brightness and set up the associated controls
  206. //
  207. if (!m_ValidBrightnessSettings.Read( m_pIWiaItem, WIA_IPS_BRIGHTNESS ))
  208. {
  209. //
  210. // Disable brightness controls
  211. //
  212. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_PROMPT ), FALSE );
  213. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_EDIT ), FALSE );
  214. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_SLIDER ), FALSE );
  215. }
  216. else
  217. {
  218. //
  219. // Enable brightness controls
  220. //
  221. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_PROMPT ), TRUE );
  222. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_EDIT ), TRUE );
  223. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_SLIDER ), TRUE );
  224. m_BrightnessSliderAndEdit.Initialize(
  225. GetDlgItem(m_hWnd,IDC_SCANPROP_BRIGHTNESS_SLIDER),
  226. GetDlgItem(m_hWnd,IDC_SCANPROP_BRIGHTNESS_EDIT),
  227. GetDlgItem(m_hWnd,IDC_SCANPROP_PREVIEW),
  228. BCPWM_SETBRIGHTNESS, &m_ValidBrightnessSettings );
  229. //
  230. // Remember that we are using this control
  231. //
  232. m_nControlsInUse |= UsingBrightness;
  233. }
  234. //
  235. // Get the valid settings for contrast and set up the associated controls
  236. //
  237. if (!m_ValidContrastSettings.Read( m_pIWiaItem, WIA_IPS_CONTRAST ))
  238. {
  239. //
  240. // Disable contrast controls
  241. //
  242. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_PROMPT ), FALSE );
  243. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_EDIT ), FALSE );
  244. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_SLIDER ), FALSE );
  245. }
  246. else
  247. {
  248. //
  249. // Enable contrast controls
  250. //
  251. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_PROMPT ), TRUE );
  252. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_EDIT ), TRUE );
  253. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_SLIDER ), TRUE );
  254. m_ContrastSliderAndEdit.Initialize(
  255. GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_SLIDER),
  256. GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_EDIT),
  257. GetDlgItem(m_hWnd,IDC_SCANPROP_PREVIEW),
  258. BCPWM_SETCONTRAST, &m_ValidContrastSettings );
  259. //
  260. // Remember that we are using this control
  261. //
  262. m_nControlsInUse |= UsingContrast;
  263. }
  264. //
  265. // Should we disable resolution? Assume yes.
  266. //
  267. bool bDisableResolution = true;
  268. //
  269. // Figure out what the *common* list of valid settings for horizontal
  270. // and vertical resolution
  271. //
  272. CValidWiaSettings HorizontalResolution;
  273. if (HorizontalResolution.Read( m_pIWiaItem, WIA_IPS_XRES ))
  274. {
  275. //
  276. // Y Resolution can be read-only, and be linked to X resolution
  277. //
  278. if (PropStorageHelpers::IsReadOnlyProperty(m_pIWiaItem, WIA_IPS_YRES))
  279. {
  280. m_ValidResolutionSettings = HorizontalResolution;
  281. //
  282. // If we made it this far, we have good resolution settings
  283. //
  284. bDisableResolution = false;
  285. }
  286. else
  287. {
  288. CValidWiaSettings VerticalResolution;
  289. if (VerticalResolution.Read( m_pIWiaItem, WIA_IPS_YRES ))
  290. {
  291. if (m_ValidResolutionSettings.FindIntersection(HorizontalResolution,VerticalResolution))
  292. {
  293. //
  294. // If we made it this far, we have good resolution settings
  295. //
  296. bDisableResolution = false;
  297. }
  298. }
  299. }
  300. }
  301. //
  302. // If we can't display resolution, disable it
  303. //
  304. if (bDisableResolution)
  305. {
  306. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_PROMPT ), FALSE );
  307. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_EDIT ), FALSE );
  308. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_UPDOWN ), FALSE );
  309. }
  310. else
  311. {
  312. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_PROMPT ), TRUE );
  313. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_EDIT ), TRUE );
  314. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_UPDOWN ), TRUE );
  315. m_ResolutionUpDownAndEdit.Initialize(
  316. GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_UPDOWN ),
  317. GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_EDIT ),
  318. &m_ValidResolutionSettings );
  319. //
  320. // Remember that we are using this control
  321. //
  322. m_nControlsInUse |= UsingResolution;
  323. }
  324. //
  325. // If we can't populate datatype, disable it
  326. //
  327. if (!PopulateDataTypes())
  328. {
  329. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_DATATYPE_PROMPT ), FALSE );
  330. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_DATATYPE_LIST ), FALSE );
  331. }
  332. else
  333. {
  334. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_DATATYPE_PROMPT ), TRUE );
  335. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_DATATYPE_LIST ), TRUE );
  336. m_nControlsInUse |= UsingDataType;
  337. }
  338. //
  339. // This means all controls were disabled
  340. //
  341. if (!m_nControlsInUse)
  342. {
  343. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESTOREDEFAULT ), FALSE );
  344. }
  345. else
  346. {
  347. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_RESTOREDEFAULT ), TRUE );
  348. }
  349. //
  350. // If we are not using brightness or contrast OR if the brightness and contrast values are not useful
  351. // for presenting meaningful feedback, disable the preview control so it doesn't mislead the user.
  352. //
  353. if (!(m_nControlsInUse & (UsingContrast|UsingBrightness)) || IsUselessPreviewRange(m_ValidBrightnessSettings) || IsUselessPreviewRange(m_ValidContrastSettings))
  354. {
  355. EnableWindow( GetDlgItem( m_hWnd, IDC_SCANPROP_PREVIEW ), FALSE );
  356. }
  357. //
  358. // Start responding to EN_CHANGE messages again
  359. //
  360. m_nProgrammaticSetting--;
  361. //
  362. // Make sure the correct image is in the thumbnail
  363. //
  364. OnDataTypeSelChange(0,0);
  365. }
  366. LRESULT CScannerCommonPropertyPage::OnInitDialog( WPARAM, LPARAM lParam )
  367. {
  368. //
  369. // Get the WIA item
  370. //
  371. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  372. if (pPropSheetPage)
  373. {
  374. m_pIWiaItem = reinterpret_cast<IWiaItem*>(pPropSheetPage->lParam);
  375. }
  376. if (!m_pIWiaItem)
  377. {
  378. return -1;
  379. }
  380. //
  381. // Load the preview control bitmaps
  382. //
  383. HBITMAP hBmpColor = reinterpret_cast<HBITMAP>(LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_SCANPROP_BITMAPPHOTO), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ));
  384. HBITMAP hBmpGrayscale = reinterpret_cast<HBITMAP>(LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_SCANPROP_BITMAPGRAYSCALE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ));
  385. HBITMAP hBmpBlackAndWhite = reinterpret_cast<HBITMAP>(LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_SCANPROP_BITMAPTEXT), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ));
  386. //
  387. // If they all loaded OK, set them
  388. //
  389. if (hBmpColor && hBmpGrayscale && hBmpBlackAndWhite)
  390. {
  391. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_LOADIMAGE, BCPWM_COLOR, reinterpret_cast<LPARAM>(hBmpColor));
  392. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_LOADIMAGE, BCPWM_GRAYSCALE, reinterpret_cast<LPARAM>(hBmpGrayscale));
  393. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_LOADIMAGE, BCPWM_BW, reinterpret_cast<LPARAM>(hBmpBlackAndWhite));
  394. }
  395. else
  396. {
  397. //
  398. // Otherwise delete all of the bitmaps
  399. //
  400. if (hBmpColor)
  401. {
  402. DeleteObject(hBmpColor);
  403. }
  404. if (hBmpGrayscale)
  405. {
  406. DeleteObject(hBmpGrayscale);
  407. }
  408. if (hBmpBlackAndWhite)
  409. {
  410. DeleteObject(hBmpBlackAndWhite);
  411. }
  412. }
  413. return TRUE;
  414. }
  415. LRESULT CScannerCommonPropertyPage::OnHScroll( WPARAM wParam, LPARAM lParam )
  416. {
  417. WIA_PUSH_FUNCTION((TEXT("CScannerCommonPropertyPage::OnHScroll( %08X, %08X )"), wParam, lParam ));
  418. if (m_nProgrammaticSetting)
  419. {
  420. return 0;
  421. }
  422. //
  423. // Contrast
  424. //
  425. if (reinterpret_cast<HWND>(lParam) == GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_SLIDER ) )
  426. {
  427. m_nProgrammaticSetting++;
  428. m_ContrastSliderAndEdit.HandleSliderUpdate();
  429. m_nProgrammaticSetting--;
  430. }
  431. //
  432. // Brightness
  433. //
  434. else if (reinterpret_cast<HWND>(lParam) == GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_SLIDER ) )
  435. {
  436. m_nProgrammaticSetting++;
  437. m_BrightnessSliderAndEdit.HandleSliderUpdate();
  438. m_nProgrammaticSetting--;
  439. }
  440. return 0;
  441. }
  442. LRESULT CScannerCommonPropertyPage::OnVScroll( WPARAM wParam, LPARAM lParam )
  443. {
  444. WIA_PUSH_FUNCTION((TEXT("CScannerCommonPropertyPage::OnVScroll( %08X, %08X )"), wParam, lParam ));
  445. if (m_nProgrammaticSetting)
  446. {
  447. return 0;
  448. }
  449. //
  450. // Resolution
  451. //
  452. if (reinterpret_cast<HWND>(lParam) == GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_UPDOWN ) )
  453. {
  454. m_nProgrammaticSetting++;
  455. m_ResolutionUpDownAndEdit.HandleUpDownUpdate();
  456. m_nProgrammaticSetting--;
  457. }
  458. return 0;
  459. }
  460. void CScannerCommonPropertyPage::OnBrightnessEditChange( WPARAM, LPARAM )
  461. {
  462. if (m_nProgrammaticSetting)
  463. {
  464. return;
  465. }
  466. m_nProgrammaticSetting++;
  467. m_BrightnessSliderAndEdit.HandleEditUpdate();
  468. m_nProgrammaticSetting--;
  469. }
  470. void CScannerCommonPropertyPage::OnContrastEditChange( WPARAM, LPARAM )
  471. {
  472. if (m_nProgrammaticSetting)
  473. {
  474. return;
  475. }
  476. m_nProgrammaticSetting++;
  477. m_ContrastSliderAndEdit.HandleEditUpdate();
  478. m_nProgrammaticSetting--;
  479. }
  480. void CScannerCommonPropertyPage::OnResolutionEditChange( WPARAM, LPARAM )
  481. {
  482. if (m_nProgrammaticSetting)
  483. {
  484. return;
  485. }
  486. m_nProgrammaticSetting++;
  487. m_ResolutionUpDownAndEdit.HandleEditUpdate();
  488. m_nProgrammaticSetting--;
  489. }
  490. void CScannerCommonPropertyPage::OnDataTypeSelChange( WPARAM, LPARAM )
  491. {
  492. if (m_nProgrammaticSetting)
  493. {
  494. return;
  495. }
  496. m_nProgrammaticSetting++;
  497. int nCurSel = static_cast<int>(SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_GETCURSEL, 0, 0 ));
  498. if (nCurSel != CB_ERR)
  499. {
  500. int nDataTypeIndex = static_cast<int>(SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_GETITEMDATA, nCurSel, 0 ));
  501. if (nDataTypeIndex >= 0 && nDataTypeIndex < AVAILABLE_COLOR_DEPTH_COUNT)
  502. {
  503. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_SETINTENT, 0, g_AvailableColorDepths[nDataTypeIndex].nPreviewWindowIntent );
  504. if (m_nControlsInUse & UsingContrast)
  505. {
  506. if (BCPWM_BW == g_AvailableColorDepths[nDataTypeIndex].nPreviewWindowIntent)
  507. {
  508. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_PROMPT), FALSE );
  509. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_PROMPT), SW_HIDE );
  510. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_SLIDER), FALSE );
  511. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_SLIDER), SW_HIDE );
  512. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_EDIT), FALSE );
  513. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_EDIT), SW_HIDE );
  514. }
  515. else
  516. {
  517. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_PROMPT), TRUE );
  518. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_PROMPT), SW_SHOW );
  519. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_SLIDER), TRUE );
  520. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_SLIDER), SW_SHOW );
  521. EnableWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_EDIT), TRUE );
  522. ShowWindow( GetDlgItem(m_hWnd,IDC_SCANPROP_CONTRAST_EDIT), SW_SHOW );
  523. }
  524. }
  525. }
  526. }
  527. m_nProgrammaticSetting--;
  528. }
  529. bool CScannerCommonPropertyPage::ValidateEditControls(void)
  530. {
  531. m_nProgrammaticSetting++;
  532. bool bSuccess = true;
  533. //
  534. // Get and set the brightness setting
  535. //
  536. if (m_nControlsInUse & UsingBrightness)
  537. {
  538. if (m_ValidBrightnessSettings.IsValid() && !m_BrightnessSliderAndEdit.ValidateEditControl())
  539. {
  540. m_BrightnessSliderAndEdit.HandleEditUpdate();
  541. m_BrightnessSliderAndEdit.HandleSliderUpdate();
  542. SetFocus( GetDlgItem( m_hWnd, IDC_SCANPROP_BRIGHTNESS_EDIT ) );
  543. CSimpleString strMessage;
  544. strMessage.Format( IDS_SCANPROP_INVALIDEDITVALUE, g_hInstance,
  545. CSimpleString( IDS_SCANPROP_BRIGHTNESS, g_hInstance ).String() );
  546. if (strMessage.Length())
  547. {
  548. MessageBox( m_hWnd,
  549. strMessage,
  550. CSimpleString( IDS_SCANPROP_ERROR_TITLE, g_hInstance ),
  551. MB_ICONINFORMATION );
  552. }
  553. bSuccess = false;
  554. }
  555. }
  556. //
  557. // Get and set the contrast setting
  558. //
  559. if (m_nControlsInUse & UsingContrast)
  560. {
  561. if (m_ValidContrastSettings.IsValid() && !m_ContrastSliderAndEdit.ValidateEditControl())
  562. {
  563. m_ContrastSliderAndEdit.HandleEditUpdate();
  564. m_ContrastSliderAndEdit.HandleSliderUpdate();
  565. SetFocus( GetDlgItem( m_hWnd, IDC_SCANPROP_CONTRAST_EDIT ) );
  566. CSimpleString strMessage;
  567. strMessage.Format( IDS_SCANPROP_INVALIDEDITVALUE, g_hInstance,
  568. CSimpleString( IDS_SCANPROP_CONTRAST, g_hInstance ).String());
  569. if (strMessage.Length())
  570. {
  571. MessageBox( m_hWnd,
  572. strMessage,
  573. CSimpleString( IDS_SCANPROP_ERROR_TITLE, g_hInstance ),
  574. MB_ICONINFORMATION );
  575. }
  576. bSuccess = false;
  577. }
  578. }
  579. //
  580. // Get and set the resolution setting
  581. //
  582. if (m_nControlsInUse & UsingResolution)
  583. {
  584. if (m_ValidResolutionSettings.IsValid() && !m_ResolutionUpDownAndEdit.ValidateEditControl())
  585. {
  586. m_ResolutionUpDownAndEdit.HandleEditUpdate();
  587. m_ResolutionUpDownAndEdit.HandleUpDownUpdate();
  588. SetFocus( GetDlgItem( m_hWnd, IDC_SCANPROP_RESOLUTION_EDIT ) );
  589. CSimpleString strMessage;
  590. strMessage.Format( IDS_SCANPROP_INVALIDEDITVALUE, g_hInstance,
  591. CSimpleString( IDS_SCANPROP_RESOLUTION, g_hInstance ).String());
  592. if (strMessage.Length())
  593. {
  594. MessageBox( m_hWnd,
  595. strMessage,
  596. CSimpleString( IDS_SCANPROP_ERROR_TITLE, g_hInstance ),
  597. MB_ICONINFORMATION );
  598. }
  599. bSuccess = false;
  600. }
  601. }
  602. //
  603. // If we made it this far, we're OK
  604. //
  605. m_nProgrammaticSetting--;
  606. return bSuccess;
  607. }
  608. bool CScannerCommonPropertyPage::ApplySettings(void)
  609. {
  610. //
  611. // Get and set the brightness setting
  612. //
  613. if (m_nControlsInUse & UsingBrightness)
  614. {
  615. LONG nBrightness = m_BrightnessSliderAndEdit.GetValueFromCurrentPos();
  616. if (!PropStorageHelpers::SetProperty( m_pIWiaItem, WIA_IPS_BRIGHTNESS, nBrightness ))
  617. {
  618. return false;
  619. }
  620. }
  621. //
  622. // Get and set the contrast setting
  623. //
  624. if (m_nControlsInUse & UsingBrightness)
  625. {
  626. LONG nContrast = m_ContrastSliderAndEdit.GetValueFromCurrentPos();
  627. if (!PropStorageHelpers::SetProperty( m_pIWiaItem, WIA_IPS_CONTRAST, nContrast ))
  628. {
  629. return false;
  630. }
  631. }
  632. //
  633. // Get and set the resolution setting
  634. //
  635. if (m_nControlsInUse & UsingResolution)
  636. {
  637. LONG nResolution = m_ResolutionUpDownAndEdit.GetValueFromCurrentPos();
  638. if (!PropStorageHelpers::SetProperty( m_pIWiaItem, WIA_IPS_XRES, nResolution ) ||
  639. (!PropStorageHelpers::IsReadOnlyProperty( m_pIWiaItem, WIA_IPS_YRES ) && !PropStorageHelpers::SetProperty( m_pIWiaItem, WIA_IPS_YRES, nResolution )))
  640. {
  641. return false;
  642. }
  643. }
  644. //
  645. // Get, validate and set the data type setting
  646. //
  647. if (m_nControlsInUse & UsingDataType)
  648. {
  649. int nCurSel = static_cast<int>(SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_GETCURSEL, 0, 0 ));
  650. if (nCurSel != CB_ERR)
  651. {
  652. int nDataTypeIndex = static_cast<int>(SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_GETITEMDATA, nCurSel, 0 ));
  653. if (nDataTypeIndex >= 0 && nDataTypeIndex < AVAILABLE_COLOR_DEPTH_COUNT)
  654. {
  655. LONG nDataType = g_AvailableColorDepths[nDataTypeIndex].nDataType;
  656. if (!PropStorageHelpers::SetProperty( m_pIWiaItem, WIA_IPA_DATATYPE, nDataType ))
  657. {
  658. return false;
  659. }
  660. }
  661. }
  662. }
  663. //
  664. // If we made it this far, we're OK
  665. //
  666. return true;
  667. }
  668. void CScannerCommonPropertyPage::OnRestoreDefault( WPARAM, LPARAM )
  669. {
  670. //
  671. // Ignore EN_CHANGE messages
  672. //
  673. m_nProgrammaticSetting++;
  674. //
  675. // Restore the brightness setting
  676. //
  677. if (m_nControlsInUse & UsingBrightness)
  678. {
  679. m_BrightnessSliderAndEdit.Restore();
  680. }
  681. //
  682. // Restore the contrast setting
  683. //
  684. if (m_nControlsInUse & UsingContrast)
  685. {
  686. m_ContrastSliderAndEdit.Restore();
  687. }
  688. //
  689. // Restore the resolution setting
  690. //
  691. if (m_nControlsInUse & UsingResolution)
  692. {
  693. m_ResolutionUpDownAndEdit.Restore();
  694. }
  695. //
  696. // Restore the data type setting
  697. //
  698. if (m_nControlsInUse & UsingDataType)
  699. {
  700. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_DATATYPE_LIST, CB_SETCURSEL, m_nInitialDataTypeSelection, 0 );
  701. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_PREVIEW, BCPWM_SETINTENT, 0, g_AvailableColorDepths[m_nInitialDataTypeSelection].nPreviewWindowIntent );
  702. }
  703. //
  704. // OK, start handling user input
  705. //
  706. m_nProgrammaticSetting--;
  707. //
  708. // Force an update of the data type controls
  709. //
  710. OnDataTypeSelChange(0,0);
  711. }
  712. LRESULT CScannerCommonPropertyPage::OnHelp( WPARAM wParam, LPARAM lParam )
  713. {
  714. return WiaHelp::HandleWmHelp( wParam, lParam, g_HelpIDs );
  715. }
  716. LRESULT CScannerCommonPropertyPage::OnContextMenu( WPARAM wParam, LPARAM lParam )
  717. {
  718. return WiaHelp::HandleWmContextMenu( wParam, lParam, g_HelpIDs );
  719. }
  720. LRESULT CScannerCommonPropertyPage::OnSysColorChange( WPARAM wParam, LPARAM lParam )
  721. {
  722. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_BRIGHTNESS_SLIDER, WM_SYSCOLORCHANGE, wParam, lParam );
  723. SendDlgItemMessage( m_hWnd, IDC_SCANPROP_CONTRAST_SLIDER, WM_SYSCOLORCHANGE, wParam, lParam );
  724. return 0;
  725. }
  726. LRESULT CScannerCommonPropertyPage::OnNotify( WPARAM wParam, LPARAM lParam )
  727. {
  728. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  729. {
  730. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_APPLY, OnApply);
  731. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_KILLACTIVE,OnKillActive);
  732. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  733. }
  734. SC_END_NOTIFY_MESSAGE_HANDLERS();
  735. }
  736. LRESULT CScannerCommonPropertyPage::OnCommand( WPARAM wParam, LPARAM lParam )
  737. {
  738. SC_BEGIN_COMMAND_HANDLERS()
  739. {
  740. SC_HANDLE_COMMAND_NOTIFY(EN_CHANGE,IDC_SCANPROP_BRIGHTNESS_EDIT,OnBrightnessEditChange);
  741. SC_HANDLE_COMMAND_NOTIFY(EN_CHANGE,IDC_SCANPROP_CONTRAST_EDIT,OnContrastEditChange);
  742. SC_HANDLE_COMMAND_NOTIFY(EN_CHANGE,IDC_SCANPROP_RESOLUTION_EDIT,OnResolutionEditChange);
  743. SC_HANDLE_COMMAND_NOTIFY(CBN_SELCHANGE,IDC_SCANPROP_DATATYPE_LIST,OnDataTypeSelChange);
  744. SC_HANDLE_COMMAND( IDC_SCANPROP_RESTOREDEFAULT, OnRestoreDefault );
  745. }
  746. SC_END_COMMAND_HANDLERS();
  747. }
  748. INT_PTR CALLBACK CScannerCommonPropertyPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  749. {
  750. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CScannerCommonPropertyPage)
  751. {
  752. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  753. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  754. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  755. SC_HANDLE_DIALOG_MESSAGE( WM_HSCROLL, OnHScroll );
  756. SC_HANDLE_DIALOG_MESSAGE( WM_VSCROLL, OnVScroll );
  757. SC_HANDLE_DIALOG_MESSAGE( WM_HELP, OnHelp );
  758. SC_HANDLE_DIALOG_MESSAGE( WM_CONTEXTMENU, OnContextMenu );
  759. SC_HANDLE_DIALOG_MESSAGE( WM_SYSCOLORCHANGE, OnSysColorChange );
  760. }
  761. SC_END_DIALOG_MESSAGE_HANDLERS();
  762. }