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.

162 lines
4.5 KiB

  1. // WiaSimpleDocPg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wiatest.h"
  5. #include "WiaSimpleDocPg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWiaSimpleDocPg property page
  13. IMPLEMENT_DYNCREATE(CWiaSimpleDocPg, CPropertyPage)
  14. CWiaSimpleDocPg::CWiaSimpleDocPg() : CPropertyPage(CWiaSimpleDocPg::IDD)
  15. {
  16. //{{AFX_DATA_INIT(CWiaSimpleDocPg)
  17. //}}AFX_DATA_INIT
  18. }
  19. CWiaSimpleDocPg::~CWiaSimpleDocPg()
  20. {
  21. }
  22. void CWiaSimpleDocPg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CPropertyPage::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CWiaSimpleDocPg)
  26. DDX_Control(pDX, IDC_NUMBEROF_PAGES_EDITBOX, m_lPages);
  27. DDX_Control(pDX, IDC_NUMBEROF_PAGES_EDITBOX_TEXT, m_lPagesText);
  28. DDX_Control(pDX, IDC_DOCUMENT_SOURCE_COMBOBOX, m_DocumentSourceComboBox);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CWiaSimpleDocPg, CPropertyPage)
  32. //{{AFX_MSG_MAP(CWiaSimpleDocPg)
  33. ON_CBN_SELCHANGE(IDC_DOCUMENT_SOURCE_COMBOBOX, OnSelchangeDocumentSourceCombobox)
  34. ON_EN_UPDATE(IDC_NUMBEROF_PAGES_EDITBOX, OnUpdateNumberofPagesEditbox)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CWiaSimpleDocPg message handlers
  39. BOOL CWiaSimpleDocPg::OnInitDialog()
  40. {
  41. CPropertyPage::OnInitDialog();
  42. m_bFirstInit = TRUE;
  43. CWiahelper WIA;
  44. WIA.SetIWiaItem(m_pIRootItem);
  45. HRESULT hr = S_OK;
  46. // set current settings
  47. LONG lDocumentHandlingSelect = 0;
  48. hr = WIA.ReadPropertyLong(WIA_DPS_DOCUMENT_HANDLING_SELECT,&lDocumentHandlingSelect);
  49. if(FAILED(hr)){
  50. ErrorMessageBox(IDS_WIATESTERROR_READINGDOCHANDLINGSELECT,hr);
  51. }
  52. if(lDocumentHandlingSelect & FEEDER){
  53. // default to feeder settings
  54. m_DocumentSourceComboBox.SetCurSel(DOCUMENT_SOURCE_FEEDER);
  55. } else {
  56. // default to flatbed settings
  57. m_DocumentSourceComboBox.SetCurSel(DOCUMENT_SOURCE_FLATBED);
  58. }
  59. LONG lPages = 0;
  60. hr = WIA.ReadPropertyLong(WIA_DPS_PAGES,&lPages);
  61. if(FAILED(hr)){
  62. ErrorMessageBox(IDS_WIATESTERROR_READINGPAGES,hr);
  63. }
  64. TCHAR szPages[MAX_PATH];
  65. memset(szPages,0,sizeof(szPages));
  66. TSPRINTF(szPages,TEXT("%d"),lPages);
  67. m_lPages.SetWindowText(szPages);
  68. // adjust UI
  69. OnSelchangeDocumentSourceCombobox();
  70. return TRUE; // return TRUE unless you set the focus to a control
  71. // EXCEPTION: OCX Property Pages should return FALSE
  72. }
  73. void CWiaSimpleDocPg::OnSelchangeDocumentSourceCombobox()
  74. {
  75. if(m_bFirstInit){
  76. m_bFirstInit = FALSE;
  77. } else {
  78. SetModified();
  79. }
  80. if (m_pIRootItem) {
  81. INT iCurSel = DOCUMENT_SOURCE_FLATBED;
  82. iCurSel = m_DocumentSourceComboBox.GetCurSel();
  83. switch (iCurSel) {
  84. case DOCUMENT_SOURCE_FLATBED:
  85. m_lPagesText.EnableWindow(FALSE);
  86. m_lPages.EnableWindow(FALSE);
  87. break;
  88. case DOCUMENT_SOURCE_FEEDER:
  89. m_lPagesText.EnableWindow(TRUE);
  90. m_lPages.EnableWindow(TRUE);
  91. break;
  92. default:
  93. break;
  94. }
  95. }
  96. }
  97. BOOL CWiaSimpleDocPg::OnApply()
  98. {
  99. HRESULT hr = S_OK;
  100. CWiahelper WIA;
  101. WIA.SetIWiaItem(m_pIRootItem);
  102. // set pages property
  103. LONG lPages = 0;
  104. lPages = (LONG)GetNumberOfPagesToAcquire();
  105. hr = WIA.WritePropertyLong(WIA_DPS_PAGES,lPages);
  106. if (FAILED(hr)) {
  107. ErrorMessageBox(IDS_WIATESTERROR_WRITINGPAGES,hr);
  108. }
  109. // set Document Handling Select property
  110. if(GetSelectedDocumentSource() == DOCUMENT_SOURCE_FLATBED){
  111. hr = WIA.WritePropertyLong(WIA_DPS_DOCUMENT_HANDLING_SELECT,FLATBED);
  112. } else {
  113. hr = WIA.WritePropertyLong(WIA_DPS_DOCUMENT_HANDLING_SELECT,FEEDER);
  114. }
  115. if (FAILED(hr)) {
  116. ErrorMessageBox(IDS_WIATESTERROR_WRITINGDOCHANDLINGSELECT,hr);
  117. }
  118. return CPropertyPage::OnApply();
  119. }
  120. int CWiaSimpleDocPg::GetSelectedDocumentSource()
  121. {
  122. return m_DocumentSourceComboBox.GetCurSel();
  123. }
  124. int CWiaSimpleDocPg::GetNumberOfPagesToAcquire()
  125. {
  126. int iPagesToAcquire = 1;
  127. TCHAR szPages[MAX_PATH];
  128. memset(szPages,0,sizeof(szPages));
  129. UpdateData();
  130. m_lPages.GetWindowText(szPages,(sizeof(szPages)/sizeof(TCHAR)));
  131. TSSCANF(szPages,TEXT("%d"),&iPagesToAcquire);
  132. return iPagesToAcquire;
  133. }
  134. void CWiaSimpleDocPg::OnUpdateNumberofPagesEditbox()
  135. {
  136. SetModified();
  137. }